问题:给定一串含中文的序列,按首字符的笔画数排序
因为默认是按拼音来排序的,
借助Globalization命名空间,包含定义区域性相关信息的类,这些信息包括语言,国家/地区,正在使用的日历,日期、货币和数字的格式模式,以及字符串的排序顺序。我们可以使用这些类编写全球化(国际化)应用程序。
CultureInfo 类,提供有关特定区域性的信息(对于非托管代码开发,则称为“区域设置”)。这些信息包括区域性的名称、书写系统、使用的日历以及对日期和排序字符串的格式化设置。LUID(locally unique identifier 全局唯一标识符)
详细参看:MSDN 循序渐进排序与字符串比较
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] s = { "件", "开", "97", "Soft", "软", "1024", "发", "广东", "繁深圳" };
//发音 LCID:0x00000804
CultureInfo PronoCi = new CultureInfo(2052);//这行要不要一样,默认
Array.Sort(s);
Console.WriteLine(" 按首字符拼音排序");
for (int i = 0; i < s.Length; i++)
{
Console.WriteLine(s[i]);
}
//笔划数 LCID:0x00020804
CultureInfo ci = new CultureInfo(133124);
Thread.CurrentThread.CurrentCulture = ci; //获取表示当前线程使用的区域性的CultureInfo
Array.Sort(s);
Console.WriteLine(" 按首字符笔画排序");
for (int i = 0; i < s.Length; i++)
{
Console.WriteLine(s[i]);
}
Console.ReadLine();
}
}
}
结果: