Fixes: U4-2635 Umbraco.Core.Strings string Rep...

...lace(this string source, string oldString, string newString,
StringComparison stringComparison) method only replaces first ocurrence
of oldString
This commit is contained in:
John
2014-04-29 13:03:52 +02:00
parent c1781c2f4b
commit 86f7d79e7a

View File

@@ -1191,17 +1191,15 @@ namespace Umbraco.Core
/// <returns>Updated string</returns>
public static string Replace(this string source, string oldString, string newString, StringComparison stringComparison)
{
var index = source.IndexOf(oldString, stringComparison);
int index;
// Determine if we found a match
var matchFound = index >= 0;
if (matchFound)
// Determine if there are any matches left in source.
while((index = source.IndexOf(oldString, stringComparison)) >= 0)
{
// Remove the old text
// Remove the old text.
source = source.Remove(index, oldString.Length);
// Add the replacemenet text
// Add the replacemenet text.
source = source.Insert(index, newString);
}