gpt4 book ai didi

c# - 在 C# 中按片假名对日语文本进行排序

转载 作者:行者123 更新时间:2023-11-30 16:28:39 24 4
gpt4 key购买 nike

是否可以按片假名对日语字符串列表进行排序?

最佳答案

当然可以。如果您使用 CultureInfo,您可以将其设置为无需查找大写/小写字母。

// 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);

如果您愿意,您可以扩展排序的功能以不区分平假名和片假名:

//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);

頑張っテください!

关于c# - 在 C# 中按片假名对日语文本进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6900061/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com