Skip to content

Commit f14ae5c

Browse files
feat: add overloaded RemovePrefix
1 parent 8e75e4d commit f14ae5c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/WouterVanRanst.Utils/Extensions/StringExtensions.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ public static string Left(this string str, int length)
1414
return str[..Math.Min(str.Length, length)];
1515
}
1616

17-
public static string RemovePrefix(this string s, string prefix, StringComparison comparisonType = StringComparison.InvariantCultureIgnoreCase)
17+
/// <summary>
18+
/// Removes the specified prefix from the beginning of the string, if it exists, using StringComparison.InvariantCultureIgnoreCase
19+
/// </summary>
20+
public static string RemovePrefix(this string s, string prefix) // NOTE: this overload exists because optional arguments cannot be used in expression trees
21+
{
22+
return RemovePrefix(s, prefix, StringComparison.InvariantCultureIgnoreCase);
23+
}
24+
25+
/// <summary>
26+
/// Removes the specified prefix from the beginning of the string, if it exists using the specified comparisonType
27+
/// </summary>
28+
public static string RemovePrefix(this string s, string prefix, StringComparison comparisonType)
1829
{
1930
if (s.StartsWith(prefix, comparisonType))
2031
return s[prefix.Length..];

0 commit comments

Comments
 (0)