Skip to content

Commit 86f7d79

Browse files
committed
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
1 parent c1781c2 commit 86f7d79

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/Umbraco.Core/StringExtensions.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,17 +1191,15 @@ public static string ToSafeFileName(this string text, CultureInfo culture)
11911191
/// <returns>Updated string</returns>
11921192
public static string Replace(this string source, string oldString, string newString, StringComparison stringComparison)
11931193
{
1194-
var index = source.IndexOf(oldString, stringComparison);
1194+
int index;
11951195

1196-
// Determine if we found a match
1197-
var matchFound = index >= 0;
1198-
1199-
if (matchFound)
1196+
// Determine if there are any matches left in source.
1197+
while((index = source.IndexOf(oldString, stringComparison)) >= 0)
12001198
{
1201-
// Remove the old text
1199+
// Remove the old text.
12021200
source = source.Remove(index, oldString.Length);
12031201

1204-
// Add the replacemenet text
1202+
// Add the replacemenet text.
12051203
source = source.Insert(index, newString);
12061204
}
12071205

0 commit comments

Comments
 (0)