add missing EnsureStartsWith
This commit is contained in:
parent
3613199917
commit
d7852e45c9
|
@ -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)}";
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue