Hans Preutz Hans Preutz - 28 days ago 6
C# Question

In C#, String .Replace wont replace danish chars

so I have string containing a Danish char (æ), say:

string textString = "tæst";
string newString = "";


for some reason this

newString = textString .Replace("æ", "e");


Is not replacing correctly, it's resulting
newString = "tæst"
when it's supposed to be
newString = "test"
.

However, NOT ALWAYS!

I have tested on multiple servers, on some this is returned correctly as
"test"
on others this is
"tæst"
.

I am thinking in terms of, maybe the string is not recognized as a utf8 string, and should maybe be forced to be recognized as a utf8. Just a guess, do you have an idea/guess?

Thanks

Answer
var s = "ӕæ".Replace("ӕ", "e"); // s = "eæ"