Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Swedish sort order for strings

Tags:

c#

sorting

linq

I am having a problem sorting Swedish strings.

I am having problems with the following characters: v, w, å, ä, ö.

new[] { "ö", "ä", "å", "wa", "va", "wb", "vb", "a"  }
.OrderBy(x => x, new CultureInfo("sv-SE").CompareInfo.GetStringComparer(CompareOptions.None))

Expected: a, va, vb, wa, wb, å, ä, ö

Actual: a, va, wa, vb, wb, å, ä, ö

Is the there any option to make it sort the strings as expected?

like image 658
Oskar Sjöberg Avatar asked May 17 '19 14:05

Oskar Sjöberg


1 Answers

As a work-around I have switched to the culture se-SE (Sami) just for sorting alphabetic strings correctly while I wait for the .NET sorting rules to be updated.

Update:

Here is the github issue: https://github.com/dotnet/corefx/issues/37753

Update2:

The issue is not with .NET, it is the sorting rules defined in the underlying operating system. This error is only present on Windows.

like image 81
Oskar Sjöberg Avatar answered Oct 22 '22 19:10

Oskar Sjöberg