String encoding - German umlaut

感情迁移 提交于 2020-01-05 04:03:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!