C # linq order depending on language

String[] a = new String[] { "NIKE", "ํ•œ๊ธ€","adidas","ํ•œ๊ธ€Korean" };

I like to order an array ํ•œ๊ธ€- first

if I just order without options. the English line is always on top.

How can i do this?

+3
source share
1 answer

Overloading OrderBytakes IComparer<string>, and you can get one of them for a specific culture using the static method Createon StringComparer. Something like this should work:

CultureInfo ci = CultureInfo.GetCultureInfo("ko-KR"); 
bool ignoreCase = true; //whether comparison should be case-sensitive
StringComparer comp = StringComparer.Create(ci, ignoreCase);

string[] unordered = //whatever
var ordered = unordered.OrderBy(s => s, comp);
+6
source

Source: https://habr.com/ru/post/1752230/


All Articles