add missing EnsureStartsWith

This commit is contained in:
ig 2023-03-20 12:53:03 +01:00
parent 3613199917
commit d7852e45c9
1 changed files with 28 additions and 0 deletions

View File

@ -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)}";
}
}