将 Unicode 字符转换为 ASCII (.NET) 中最接近(最相似)的字符
如何将不同的 Unicode 字符转换为其最接近的 ASCII 等效字符?喜欢 ä ->答:我用谷歌搜索但没有找到任何合适的解决方案。 Encoding.ASCII.GetBytes("Ä")[0]
这个技巧不起作用。 (结果是?
)。
我发现有一个类 Encoder
具有 Fallback
属性,该属性恰好适用于 char
无法转换的情况,但实现( EncoderReplacementFallback
) 很愚蠢并转换为 ?
。
有什么想法吗?
How do I to convert different Unicode characters to their closest ASCII equivalents? Like Ä -> A. I googled but didn't find any suitable solution. The trick Encoding.ASCII.GetBytes("Ä")[0]
didn't work. (Result was ?
).
I found that there is a class Encoder
that has a Fallback
property that is exactly for cases when char
can't be converted, but implementations (EncoderReplacementFallback
) are stupid and convert to ?
.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果只是删除变音符号,则前往这个答案:
If it is just removing of the diacritical marks, then head to this answer:
MS Dynamics 存在一个问题,它不允许 x20 到 x7f 之外的任何字符,并且该范围内的某些字符也是无效的。我的答案是创建一个以无效字符为键的数组,返回有效字符的最佳猜测。
它不太漂亮,但它有效。
你的答案必然会有所不同。
MS Dynamics has a problem where it won't allow for any character outside of x20 to x7f and some characters within that range are also invalid. My answer was to create an array keyed to the invalid characters returning the best guess of the valid characters.
It ain't pretty, but it works.
Your answer is necessarily going to be different.