views:

274

answers:

4

Hi,

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

+1  A: 

Try using range selection instead of precise matching.

A: (firstLetter <= A)
B: (firstLetter > A) AND (firstLetter <= B)
...
Developer Art
+1  A: 

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.

Joey
+5  A: 

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

bdukes
Thanks, that's the one
Michel
+4  A: 

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
Fredrik Mörk
+1 as I was going to answer - just use a culture that considers "A" and "Å" to be the same letter.
Rex M