用 C# 中未修饰的对应字符替换重音/变音字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/382917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replacing accented/umlauted characters with their unadorned counterparts in C#
提问by Andrew Rollings
Duplicate of 249087
重复的249087
I have a bunch of user generated addresses that may contain characters with diacritic marks. What is the most effective (i.e. generic) way (apart from a straightforward replace) to automatically convert any such characters to their closest English equivalent?
我有一堆用户生成的地址,其中可能包含带有变音符号的字符。将任何此类字符自动转换为最接近的英语等价物的最有效(即通用)方式(除了直接替换)是什么?
E.g. any of àa???would become a
例如任何àa??? 将成为一个
?would become the two separate letters ae
? 将成为两个独立的字母ae
?would become c
? 会变成c
any of èéê?would become e
任何èéê ?会变成e
etc. for all possible letter variations (preferably without having to find and encode lookups for each diacritic form of the letter).
等所有可能的字母变体(最好不必为字母的每个变音符号形式查找和编码查找)。
(Note: I have to pass these addresses on to third party software that is incapable of printing anything other than English characters. I'd rather the software was capable of handling them, but I have no control over that.)
(注意:我必须将这些地址传递给无法打印除英文字符以外的任何内容的第三方软件。我希望该软件能够处理它们,但我无法控制。)
EDIT: Never mind... Found the answer [here][2]. It showed up in the "Related" section to the right of the question after I posted, but notin my prior search or as a pre-post suggestion. Hmm. I added the 'diacritics' tag to the other question in any case.
编辑:没关系......找到答案[here][2]。它出现在我发布后问题右侧的“相关”部分,但不在我之前的搜索中或作为发布前的建议。唔。无论如何,我在另一个问题中添加了“变音符号”标签。
EDIT 2: Jeez! Who voted this -1 after I closed it?
编辑2:天哪!我关闭后谁投了这个-1?
采纳答案by devstuff
Just was going to post the same link :-)
只是要发布相同的链接:-)
Sounds like you're doing this already, but I would recommend that you store the original string for display in your application, and only do this for the 3rd-party stuff. People get cranky if they don't think their real name is important :-)
听起来您已经这样做了,但我建议您将原始字符串存储在您的应用程序中以供显示,并且仅对第 3 方内容执行此操作。如果人们认为自己的真名不重要,他们就会变得暴躁 :-)