OrderBy with Swedish letters

后端 未结 4 854
旧巷少年郎
旧巷少年郎 2021-01-04 08:19

I have a list of my custom class Customer and I want to sort them alphabetically by Title. So I wrote

myList = myList.OrderByDescending(x => x.Title).ToL         


        
相关标签:
4条回答
  • 2021-01-04 08:36

    The workaround I found for a somewhat similar problem was to have a secondary field that held the converted version of the data.
    In my case, we had person.Name and person.SearchName, where SearchName was Name converted to have no diacritics.

    But this was only the best approach (AFAIK) because we wanted a speedy db search/filtering and then instantiating only the relevant results.
    If you already have the objects in memory I would advise going with one of the other approaches; and not this one.

    0 讨论(0)
  • 2021-01-04 08:40

    I my case: _My sorting list have value was encoded. This make my order incorrect. Add decoded solving my problems !

    0 讨论(0)
  • 2021-01-04 08:55

    You can use culture specific StringComparer, see here.

    CultureInfo culture = new CultureInfo("sv-SE");
    var result = myList.OrderByDescending(x => 
                   x.Title, StringComparer.Create(culture, false));
    
    0 讨论(0)
  • 2021-01-04 08:57

    Set the Thread.CurrentCulture property to the correct culture.

    0 讨论(0)
提交回复
热议问题