diff --git a/csharp/Lib/Utils/StringUtils.cs b/csharp/Lib/Utils/StringUtils.cs index e0ee21746..46372e381 100644 --- a/csharp/Lib/Utils/StringUtils.cs +++ b/csharp/Lib/Utils/StringUtils.cs @@ -352,6 +352,34 @@ public static class StringUtils } + public static String TrimStart(this String target, String trimString) + { + if (String.IsNullOrEmpty(trimString)) return target; + + var result = target; + while (result.StartsWith(trimString)) + result = result[trimString.Length..]; + + return result; + } + + + public static String TrimEnd(this String target, String trimString) + { + if (String.IsNullOrEmpty(trimString)) + return target; + + var result = target; + while (result.EndsWith(trimString)) + result = result[..^trimString.Length]; + + return result; + } + + public static String EnsureStartsWith(this String target, String prefix) + { + return $"{prefix}{target.TrimStart(prefix)}"; + } } \ No newline at end of file