Asp.Net/C#, when is A equal to A? (and É equals E)

I swap countries in alpha, so countries starting AD, EH, etc. But I also want to list åbrohw in a, and "pollewop" on e. I tried string.startswith with the stringcompare parameter, but it does not work ...

I run under the sv-SE culture code if that matters ...

Michelle

+4
source share
4 answers

See How to remove diacritical characters (accents) from a string in .NET? to solve the problem of creating a version without diacritics, which you can use for comparison (while the version with diacritics is still displayed).

+6
source

Oh yes, 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 result:

 sv-SE: A B Å en-GB: A Å B 
+4
source

Try using range selection instead of exact match.

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

You will need to specify a specific culture for sorting or write your own comparer for this. The default sort order for Swedish puts å, ä, ö at the end.

Most likely, you would like to expand the letters with diacritics and sort them as if they did not have a diacritic mark.

+1
source

All Articles