如何检查 .Net 中的 Unicode 字符是否有变音符号?
我正在开发一种用于自动语言检测的启发式方法,并且想找出给定的字母是否具有变音符号(例如“Ðàäèî Êóëüòóðà” - 所有字母都有变音符号)。如果可能的话,如果我也能得到变音符号的类型,那就最好了。
我浏览了 UnicodeCategory
枚举,但没有找到任何可以帮助我的东西。
I am developing a heuristic for automatic language detection and would like to find out whether the given letter has diacritics (like "Ðàäèî Êóëüòóðà" -- all letters have diacritics). It would be best if I could also get the type of diacritic, if possible.
I browsed through UnicodeCategory
enum but didn't find anything that could help me here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种可能的方法是将其标准化为将字母及其变音符号写成多个代码点的形式。然后检查是否有字母后跟重音符号。
改编自 如何删除变音符号(重音符号)来自 .NET 中的字符串?,您可以使用
Normalize(NormalizationForm.FormD)
进行规范化,并使用以下命令检查变音符号UnicodeCategory.NonSpacingMark
。One possible way is to normalize it to a form where letters and their diacritics are written as several codepoints. Then check if you have a letter followed by accents.
Adapting from How do I remove diacritics (accents) from a string in .NET?, you can normalize with
Normalize(NormalizationForm.FormD)
and check for the diacritics withUnicodeCategory.NonSpacingMark
.试试这个:
Try this: