C# 中的变音符号按字母顺序排列
我想知道如何在 C Sharp 中对人们的全名以及该语言的变音符号进行可靠的字母顺序排序(对于列表框)?
提前致谢。
问:所以您只想将变音符号视为“原始”字母? (例如:João 与 Joao 相同)? – NullUserException
A:我想按照我定义的语言应有的方式对待它们,尊重人们应用的字母顺序规则每天。我确信它是用每种语言的语法编写的。谢谢。 – 奎普斯
I want to know how do you perform a reliable alphabetical ordering (for a listbox) of people's full names with the diacritics of the language in C sharp?
Thanks in advance.
Q: So you just want to treat diacritics as the "original" letter? (eg: João is the same as Joao)? – NullUserException
A: I want to treat them as they should be treated in the language I define, respecting the rules of alphabetical ordering that people apply everyday. I'm sure it's written in the grammars of each language. Thanks. – Queops
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这篇 MSDN 文章应该可以满足您的需求: 比较和排序特定文化的数据。它通过代码示例描述了文化敏感的比较、排序和规范化。
This MSDN article should give you what you need: Comparing and Sorting Data for a Specific Culture. It describes culture sensitive comparison, sorting, and normalization, with code samples.
您可以使用 s.Normalize(NormalizationForm.FormD) 规范化字符串 s,将重音字符分隔为非重音字符,后跟重音符号。然后,您可以使用
CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.NonSpacingMark
来识别标准化s
中的重音字符c
。鉴于此,您可以实现自己的字符串比较运算符,以对重音进行所需的任何排序。You can use
s.Normalize(NormalizationForm.FormD)
to normalize a strings
, separating accented characters into unaccented characters followed by the accent symbol. You can then useCharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.NonSpacingMark
to identify accent charactersc
in the normalizeds
. Given that, you can implement your own string comparison operator to place whatever ordering you need on accents.