Reputation: 1202
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
Upvotes: 2
Views: 975
Reputation: 441
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.
Upvotes: 5
Reputation: 5295
You can use s.Normalize(NormalizationForm.FormD)
to normalize a string s
, separating accented characters into unaccented characters followed by the accent symbol. You can then use CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.NonSpacingMark
to identify accent characters c
in the normalized s
. Given that, you can implement your own string comparison operator to place whatever ordering you need on accents.
Upvotes: 0