C#中汉字排序简单示例(拼音/笔划)
可以按照区域语言修改排序规则。
class Program { static void Main(string[] args) { string[] arr = { "趙(ZHAO)", "錢(QIAN)", "孫(SUN)", "李(LI)", "周(ZHOU)", "吳(WU)", "鄭(ZHENG)", "王(WANG)"}; //发音 LCID:0x00000804 CultureInfo PronoCi = new CultureInfo(2052); //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us"); Array.Sort(arr); Console.WriteLine("按发音排序:"); for (int i = arr.GetLowerBound(0); i <= arr.GetUpperBound(0); i++) Console.WriteLine("[{0}]:\t{1}", i, arr.GetValue(i)); Console.WriteLine(); //笔画数 LCID:0x00020804 CultureInfo StrokCi = new CultureInfo(133124); Thread.CurrentThread.CurrentCulture = StrokCi; Array.Sort(arr); Console.WriteLine("按笔划数排序:"); for (int i = arr.GetLowerBound(0); i <= arr.GetUpperBound(0); i++) Console.WriteLine("[{0}]:\t{1}", i, arr.GetValue(i)); Console.WriteLine(); //zh-cn (拼音:简中) Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-cn"); Array.Sort(arr); Console.WriteLine("zh-cn:"); for (int i = arr.GetLowerBound(0); i <= arr.GetUpperBound(0); i++) Console.WriteLine("[{0}]:\t{1}", i, arr.GetValue(i)); Console.WriteLine(); //zh-tw (笔划数:繁中) Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-tw"); Array.Sort(arr); Console.WriteLine("zh-tw:"); for (int i = arr.GetLowerBound(0); i <= arr.GetUpperBound(0); i++) Console.WriteLine("[{0}]:\t{1}", i, arr.GetValue(i)); Console.ReadKey(); } }
作者:阿笨
【官方QQ一群:跟着阿笨一起玩NET(已满)】:422315558
【官方QQ二群:跟着阿笨一起玩C#(已满)】:574187616
【官方QQ三群:跟着阿笨一起玩ASP.NET(已满)】:967920586
【官方QQ四群:Asp.Net Core跨平台技术开发(可加入)】:829227829
【官方QQ五群:.NET Core跨平台开发技术(可加入)】:647639415
【网易云课堂】:https://study.163.com/provider/2544628/index.htm?share=2&shareId=2544628
【腾讯课堂】:https://abennet.ke.qq.com
【51CTO学院】:https://edu.51cto.com/sd/66c64
【微信公众号】:微信搜索:跟着阿笨一起玩NET