From 86f7d79e7a326a90c299c5777dbaff8dc9a95f99 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 29 Apr 2014 13:03:52 +0200 Subject: [PATCH] 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 --- src/Umbraco.Core/StringExtensions.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index 6a2784cc98..0da99b42f0 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -1191,17 +1191,15 @@ namespace Umbraco.Core /// Updated string 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); }