字符串编码-德语变音符号 [英] String encoding - German umlaut

查看:282
本文介绍了字符串编码-德语变音符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#,Framework 4.0,德语面临一个棘手的问题.

Using C#, Framework 4.0, I'm facing a tricky problem with the german language.

考虑此snippet:

string l_stest = "ZÄHLWERKE";
Console.WriteLine(l_stest.Length); // 9
Console.WriteLine(toto.LengthInTextElements); // 9
Console.ReadLine();

结果将为9;

现在,用Notepad++选择文本,它的长度为10.

Now, selecting the text withing Notepad++, it will give me a length of 10.

我猜想encoding是我的问题的根源,但不必扫描我的单词并用匹配的两个字母(Ä-> AE)替换Umlauts,如何继续计算正是我的琴弦长度?

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 ?

我认为正确的长度是10.

提前谢谢!

推荐答案

Encoding.UTF8.GetByteCount(l_stest)看起来像您想要的长度.

Encoding.UTF8.GetByteCount(l_stest) looks like it'll get the length you want.

这篇关于字符串编码-德语变音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆