Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 833
Michel Avatar asked Dec 18 '22 05:12

Michel


2 Answers

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

like image 110
bdukes Avatar answered Jan 07 '23 04:01

bdukes


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
like image 36
Fredrik Mörk Avatar answered Jan 07 '23 03:01

Fredrik Mörk