Browse Source

Add String.StripEnd extension

pull/333/head
Ionite 1 year ago
parent
commit
5063fad986
No known key found for this signature in database
  1. 15
      StabilityMatrix.Core/Extensions/StringExtensions.cs

15
StabilityMatrix.Core/Extensions/StringExtensions.cs

@ -1,4 +1,5 @@
using System.Text;
using System.Diagnostics.Contracts;
using System.Text;
using System.Text.RegularExpressions;
namespace StabilityMatrix.Core.Extensions;
@ -80,15 +81,27 @@ public static class StringExtensions
/// <summary>
/// Strips the substring from the start of the string
/// </summary>
[Pure]
public static string StripStart(this string str, string subString)
{
var index = str.IndexOf(subString, StringComparison.Ordinal);
return index < 0 ? str : str.Remove(index, subString.Length);
}
/// <summary>
/// Strips the substring from the end of the string
/// </summary>
[Pure]
public static string StripEnd(this string str, string subString)
{
var index = str.LastIndexOf(subString, StringComparison.Ordinal);
return index < 0 ? str : str.Remove(index, subString.Length);
}
/// <summary>
/// Splits lines by \n and \r\n
/// </summary>
[Pure]
// ReSharper disable once ReturnTypeCanBeEnumerable.Global
public static string[] SplitLines(
this string str,

Loading…
Cancel
Save