Reputation: 23635
i'm paging countries in an alfabet, so countries starting A-D, E-H etc. But i also want to list åbrohw at the a, and ëpollewop at the e. I tried string.startswith providing a stringcompare option, but it doesn't work...
i'm running under the sv-SE culture code, if that matters...
Michel
Upvotes: 4
Views: 881
Reputation: 158349
Oh yes, the culture matters. If you run the following:
List<string> letters = new List<string>() { "Å", "B", "A" };
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("sv-SE");
letters.Sort();
Console.WriteLine("sv-SE:")
letters.ForEach(s => Console.WriteLine(s));
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB");
letters.Sort();
Console.WriteLine("en-GB:")
letters.ForEach(s => Console.WriteLine(s));
...you get the following output:
sv-SE:
A
B
Å
en-GB:
A
Å
B
Upvotes: 4
Reputation: 156005
See How do I remove diacritics (accents) from a string in .NET? for the solution to create a version without the diacritics, which you can use for the comparisons (while still displaying the version with the diacritics).
Upvotes: 6
Reputation: 354714
You would have to give a specific culture for sorting or write your own comparer for that. Default sorting order for Swedish puts å, ä, ö at the end.
Most likely you would like to decompose letters with diacritics and sort them as if they wouldn't have a diacritic mark.
Upvotes: 1
Reputation:
Try using range selection instead of precise matching.
A: (firstLetter <= A)
B: (firstLetter > A) AND (firstLetter <= B)
...
Upvotes: 1