ReplaceFirst string extension
This commit is contained in:
@@ -182,4 +182,15 @@ public static class StringExtensions
|
||||
|
||||
return input.Substring(0, maxLength - 3) + "...";
|
||||
}
|
||||
|
||||
|
||||
public static string ReplaceFirst(this string text, string search, string replace)
|
||||
{
|
||||
int pos = text.IndexOf(search);
|
||||
if (pos < 0)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user