如何比较 Unicode 字符串以使看起来相同的字符串同等比较?
许多编码的 Unicode 字符序列具有相同的视觉表示和相同的计算含义。
ñ 字符可以通过两种方式进行编码:
U+00F1: ñ (LATIN SMALL LETTER N WITH TIDLE)
或:
U+006E: n (LATIN SMALL LETTER N)
U+0303: ~ (COMBINING TILDE)
这会创建 10 个不同的字节序列,显示为 ñ:
U+00F1 in UTF-8, UTF-16LE, UTF-16BE, UTF-32BE, UTF32-LE
U+006E followed by U+0303 UTF-8, UTF-16LE, UTF-16BE, UTF-32BE, UTF32-LE
是否有任何直接的方法来比较 Unicode 字符串(我对从各种 UTF 表示形式解码的 unicode 字符感到满意)和发现它们是一样的吗?也就是说,我想要一些东西告诉我 U+00F1 与 U+0303 U+006E 相同,
谢谢。
Many sequences of encoded Unicode characters have the same visual representation and the same computational meaning.
The ñ character can be coded two ways:
U+00F1: ñ (LATIN SMALL LETTER N WITH TIDLE)
or:
U+006E: n (LATIN SMALL LETTER N)
U+0303: ~ (COMBINING TILDE)
This creates 10 different byte sequences that display as ñ:
U+00F1 in UTF-8, UTF-16LE, UTF-16BE, UTF-32BE, UTF32-LE
U+006E followed by U+0303 UTF-8, UTF-16LE, UTF-16BE, UTF-32BE, UTF32-LE
Is there any straightforward way to compare Unicode strings (I'm happy with unicode characters that have been decoded from the various UTF representations) and find out that they are the same? That is, I want something that tells me that U+00F1 is the same as U+0303 U+006E
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个过程称为规范化,任何像样的 Unicode 库都支持。背景资料在这里。
The process is called normalization, supported by any decent Unicode library. Backgrounder is here.