zoukankan      html  css  js  c++  java
  • C# 中文序列按笔画排序

    问题:给定一串含中文的序列,按首字符的笔画数排序

    因为默认是按拼音来排序的,

    借助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();
            }
        }
    }
    View Code

    结果:


  • 相关阅读:
    Expression Blend实例中文教程(13)
    Expression Blend实例中文教程(12)
    Expression Blend实例中文教程(11)
    【转】Python3中urllib详细使用方法(header,代理,超时,认证,异常处理)
    cookie
    【转】cookielib模块
    代理的步骤
    urllib.parse.urlencode
    urllib.request.Request
    【转】python3 urllib.request 网络请求操作
  • 原文地址:https://www.cnblogs.com/peterYong/p/6556604.html
Copyright © 2011-2022 走看看