简体   繁体   English

捷克语中的c#排序数组

[英]c# Sorting array in Czech

I have problem sorting an array with Czech names. 我用捷克语名称对数组进行排序时遇到问题。 I have such array: 我有这样的数组:

    var myList = new[]
    {
        "Čas revize", "Datum kalibrace", "Chybové kódy"
    };

and try to sort it like this: 并尝试将其排序为:

CultureInfo culture = new CultureInfo("cs-CZ");
var result = myList.OrderBy(x => x, StringComparer.Create(culture, true));

So I expect that the data will be sorted as follows: 因此,我希望数据将按以下方式排序:

"Čas revize", "Chybové kódy", "Datum kalibrace"

But it end it up in different order: 但这以不同的顺序结束:

"Čas revize", "Datum kalibrace", "Chybové kódy"

Interesting question. 有趣的问题。 If you read the documentation 如果您阅读文档

In Czech - Czech Republic culture, "ch" is a single character that is greater than "d". 在捷克语-捷克共和国文化中,“ ch”是单个字符,大于“ d”。 However, in English - United States culture, "ch" consists of two characters, and "c" is less than "d". 但是,在英语-美国文化中,“ ch”由两个字符组成,“ c”小于“ d”。

The Czech alphabet is ordered 捷克字母是有序的

A Á BC Č D Ď E É Ě FGH Ch I Í JKLMN Ň O Ó PQR Ř S Š T Ť U Ú Ů VWXY Ý Z Ž A BCČDĎEÉĚFGH Ch IÍJKLMNŇOÓPQRŘSŠTŤUŮVWXYÝZŽ

So the ordering of your array is correct. 因此,数组的顺序是正确的。

I just tested this: 我刚刚测试了这个:

List<string> myList = new List<string> { "Čas revize", "Datum kalibrace", "Chybové kódy", "óóó", "ČČČ", "aaa", "ééé", "èèè", "êêê", "fff", "Code" };
CultureInfo culture = new CultureInfo ("cs-CZ");
List<string> result = myList.OrderBy (x => x, StringComparer.Create (culture, true)).ToList ();

And got the result: 并得到结果:

aaa Code 'Čas revize' ČČČ 'Datum kalibrace' ééé èèè êêê fff Chybové kódy óóó aaa编码'Časrevize'ČČČ'Datum kalibrace'éééèèèêêêêêfffChybovékódyóóó

Then I tested this: 然后,我对此进行了测试:

List<string> myList = new List<string> { "Čas revize", "Datum kalibrace", "Chybové kódy", "óóó", "ČČČ", "aaa", "ééé", "èèè", "êêê", "fff", "Code" };
List<string> result = myList.OrderBy (j => j).ToList ();

And got this result: 并得到以下结果:

aaa 'Čas revize' ČČČ 'Chybové kódy' Code 'Datum kalibrace' ééé èèè êêê fff óóó aaa'Časrevize'ČČČ'Chybovékódy'代码'Datum kalibrace'éééèèèêêêêêfffóóó

It looks like the 'C' in Chybové is a different character than a normal 'C'. 看起来Chybové中的'C'与普通的'C'不同。 Or that 'Ch' or 'Chy' may have it's own position in your alphabet. 或者“ Ch”或“ Chy”在字母表中可能有自己的位置。 But without the CultureInfo, it seems to treat it correctly regardless of special characters. 但是,如果没有CultureInfo,则似乎可以正确对待它,而不必考虑特殊字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM