Search code examples
c#stringinternationalizationlocale

C# sort list of strings with specific scandinavian culture in mind


i have a list of country names. Now i want to sort them alphabeticly, with the users culture in mind. I have the 4 scandinavian cultures norway, sweden, danmark en finland.

For sweden, the Ö (O with two dots if it's not printed correctly) must appear at the end, after the Z, but for danmark it's just the letter O, so it must appear after the N.

I already did some work to create an O for the Ö for danmark but keep it an Ö for Sweden.

But List.sort doesn't have an overload for a cultureinfo, only for a stringcomparer. But in the stringcomparer a can't provide a cultureinfo?

Michel


Solution

  • If you are using C# you can try this

    List<string> s = new List<string>();
                s.Sort(delegate(string item1, string item2) { return String.Compare(item1,item2, false, new CultureInfo("")); });