OrderBy仅在我的计算机上不起作用

问题描述

我们有一个用于数据库的旧式传统db gen工具。我可以更改内容,而无需实际更改。我将其归结为列的排序。

Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("sv-SE");
var sortThis = new[] { "VatNumber","VisiAvtalsnummerCompanies","WinZipPassword" }
    .OrderBy(s => s,StringComparer.CurrentCultureIgnoreCase)
    .ToList();

在瑞典文化中,输出应为“ VatNumber”,“ VisiAvtalsnummerCompanies”,“ WinZipPassword”,字母V排在W之前。

但是在我的计算机上,输出为“ VatNumber”,“ WinZipPassword”,“ VisiAvtalsnummerCompanies”

C#小提琴上的服务器输出正确

https://dotnetfiddle.net/sXJjD6

编辑:

StringComparer.Create(new CultureInfo("sv-SE"),true)
                .Compare("V","W"); // -1  correct

StringComparer.Create(new CultureInfo("sv-SE"),true)
                .Compare("VB","WA"); // 1  incorrect

解决方法

在2006年之前,似乎用瑞典语对V和W进行了同样的排序:似乎瑞典语并没有真正使用W(名称和输入单词除外),并且有时将V和W互换使用,因此这种排序顺序选择它是为了减少混乱[1]。

早在2006年,SAOL的第13版(瑞典语参考词典,Svenska Akademiens OrdLista)宣称W本身就是一个字母,并开始被作为对V的单独字母进行排序。 / p>

CLDR是Unicode通用语言环境数据存储库,它定义了此类内容,它为瑞典语引入了两种归类:“标准”和“已重组”。他们在2007年将默认排序规则更改为“ reformed” [2],这将对使用CLDR作为参考的任何内容产生影响。

在1903年更新中,Windows集成了使用CLDR数据的Unicode国际组件(ICU)。但是,这只会影响.NET 5:.NET的早期版本仍应使用国家语言支持(NLS)库[3]。

我无法找到有关1909年至2004年之间NLS更改的任何数据。我不知道他们最终可能赶上了CLDR。在Windows 7中对排序进行了一些重大更改,但是自[4]以来我什么都找不到。如果您的目标是.NET 5,并且是从1903年升级的,那么我可以解释一下。

如果目标是.NET 5+或在Linux上运行,则应该一直使用CLDR数据。

[1]:https://en.wikipedia.org/wiki/Swedish_alphabet#Uncommon_letters
[2]:https://github.com/unicode-org/cldr/commit/aaa134f4f74db91b781be1c8b9d9e9f1fd123c0e
[3]:https://docs.microsoft.com/en-us/dotnet/standard/globalization-localization/globalization-icu
[4]:https://docs.microsoft.com/en-us/windows/win32/win7appqual/nls-sorting-changes

我遇到的其他随机链接,但不构成我的答案的一部分:

  1. https://unicode-org.atlassian.net/browse/CLDR-1035#icft=CLDR-1035
  2. https://unicode-org.atlassian.net/browse/CLDR-2143?jql=text%20~%20%22swedish%20collation%22
  3. https://sourceware.org/bugzilla/show_bug.cgi?id=9724
  4. https://bugzilla.redhat.com/show_bug.cgi?id=17005
  5. Sort list of tuples considering locale (swedish ordering)
  6. http://www.softwolves.pp.se/misc/arkiv/sv/18/9009.html
  7. How to get Swedish sort order for strings
  8. https://github.com/dotnet/runtime/issues/29592

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...