问题
Using C#, Framework 4.0, I'm facing a tricky problem with the german language.
Considering this snippet :
string l_stest = "ZÄHLWERKE";
Console.WriteLine(l_stest.Length); // 9
Console.WriteLine(toto.LengthInTextElements); // 9
Console.ReadLine();
The result will be 9;
Now, selecting the text withing Notepad++, it will give me a length of 10.
I'm guessing the encoding is the source of my problem but without having to scan my words and replace the Umlauts by the matching two letters (Ä -> AE), how can I proceed to calculate precisely the length of my strings ?
Edit : I consider the correct length is 10.
Thanks in advance !
回答1:
Encoding.UTF8.GetByteCount(l_stest) looks like it'll get the length you want.
来源:https://stackoverflow.com/questions/13641627/string-encoding-german-umlaut