Sorting Japanese text by Katakana in C#
Is it possible to sort a list of Japanese strings by th开发者_高级运维eir Katakana?
Sure you can. If you use CultureInfo, you can make it so it doesn't bother looking for upper/lower-case.
// Create CultureInfo
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ja-JP");
//Create the StringComparer
StringComparer cmp = StringComparer.Create(ci, true);
// Sort your array of string
Array.Sort(myArray, cmp);
You can extend the functinality of the sort to not distinguish between Hiragana and Katakana if you like by doing this:
//Create CultureInfo
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ja-JP");
// Set it so it ignores the kana type
CultureInfoCompare cmp =
new CultureInfoCompare(ci, System.Globalization.CompareOptions.IgnoreKanaType);
//Sort it
Array.Sort(myArray, cmp);
頑張ってください!
Yes, sure you can sort katakana strings by their constituent characters. But this will only work if you are only interested in a subset of the Japanese language. In general Japanese strings are made up of hiragana, katakana and kanji.
If you want basic Japanese language sorting, I would use kakasi to convert kanji to hiragana and then decide how you want to order hiragana and katakana; personally I would be tempted to do あ, ア, い, イ, う, ウ, etc.
精彩评论