ReplaceFirst string extension

This commit is contained in:
2022-06-23 16:13:57 +02:00
parent 579a13f453
commit a84758aa21
+11
View File
@@ -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);
}
}