Question

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

Was it helpful?

Solution

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).

OTHER TIPS

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

Try using range selection instead of precise matching.

A: (firstLetter <= A)
B: (firstLetter > A) AND (firstLetter <= B)
...

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top