string s = "Gewerbegebiet Waldstraße"; //other possible input "Waldstrasse"
int iFoundStart = s.IndexOf("strasse", StringComparison.CurrentCulture);
if (iFoundStart > -1)
s = s.Remove(iFoundStart, 7);
I'm running CultureInfo 1031 (german).
IndexOf matches 'straße' or 'strasse' with defined 'strasse' and returns 18 as position.
Neither Remove nor Replace got any overload for setting a culture.
If I remove 6 chars using Remove 1 character will be left if input-string is 'strasse' and 'straße' will work. If input-string is 'straße' and I remove 7 chars I get ArgumentOutOfRangeException.
Is there a way to safely remove the found string? Any method which provides the last index of IndexOf? I stepped closer into IndexOf and it's native code under the hood as expected - so no way to do something own...
s = s.Replace("strasse","");
– Shrierstring.Replace
doesn't take the culture into account, so "ss" doesn't match "ß". – Acadiaen-US
and got this problem.the thing is IndexOf behaves different. – Frostbites.Replace("ß", "ss");
? – AcadiaStringComparison.Ordinal
then it gives me-1
of course but .Net guys should think about adding this overloads forReplace
andRemove
methods too and they should behave likeIndexOf
do. – Frostbite