Introducing ReplaceFirst() as string extension instead of using the CDF one
This commit is contained in:
@@ -938,7 +938,22 @@ namespace Umbraco.Core
|
||||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new string in which only the first occurrence of a specified string is replaced by a specified replacement string.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to filter.</param>
|
||||
/// <param name="search">The string to replace.</param>
|
||||
/// <param name="replace">The replacement string.</param>
|
||||
/// <returns>The filtered string.</returns>
|
||||
public static string ReplaceFirst(this string text, string search, string replace)
|
||||
{
|
||||
var 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