Skip to content
Permalink
Browse files

Fix ReplaceAll

  • Loading branch information...
mythz committed Aug 28, 2019
1 parent fee0f67 commit 923e66623d5573367a72a441e886926b990a482a
@@ -913,8 +913,9 @@ public static string ReplaceAll(this string haystack, string needle, string repl
{
int pos;
// Avoid a possible infinite loop
if (needle == replacement) return haystack;
while ((pos = haystack.IndexOf(needle, StringComparison.Ordinal)) > 0)
if (needle == replacement)
return haystack;
while ((pos = haystack.IndexOf(needle, StringComparison.Ordinal)) >= 0)
{
haystack = haystack.Substring(0, pos)
+ replacement
@@ -355,5 +355,12 @@ public void Does_ContainsAny_Return_CaseInsensitive_Matches()

Assert.That(input.ContainsAny(testMatches, StringComparison.OrdinalIgnoreCase));
}

[Test]
public void Does_ReplaceAll_from_Start()
{
Assert.That("/images".ReplaceAll("/",""), Is.EqualTo("images"));
}

}
}

0 comments on commit 923e666

Please sign in to comment.
You can’t perform that action at this time.