zoukankan      html  css  js  c++  java
  • c#提出中文首字母

           /// <summary>  
            
    /// 获取中文字符串的首字母  
            
    /// </summary>  
            
    /// <param name="strText"></param>  
            
    /// <returns></returns>  
            public static string GetChineseSpell(string strText)
            {
                int len = strText.Length;
                string myStr = "";
                for (int i = 0; i < len; i++)
                {
                    myStr += getSpell(strText.Substring(i, 1));
                }
                return myStr;
            }

            /// <summary>  
            
    /// 获取单个中文的首字母  
            
    /// </summary>  
            
    /// <param name="cnChar"></param>  
            
    /// <returns></returns>  
            private static string getSpell(string cnChar)
            {
                byte[] arrCN = Encoding.Default.GetBytes(cnChar);
                if (arrCN.Length > 1)
                {
                    int area = (short)arrCN[0];
                    int pos = (short)arrCN[1];
                    int code = (area << 8) + pos;
                    int[] areacode = { 4521745253457614631846826470104729747614481194811949062493244989650371506145062250906513875144652218526985269852698529805368954481 };

                    for (int i = 0; i < 26; i++)
                    {
                        int max = 55290;
                        if (i != 25)
                        {
                            max = areacode[i + 1];
                        }
                        if (areacode[i] <= code && code < max)
                        {
                            return Encoding.Default.GetString(new byte[] { (byte)(97 + i) });
                        }
                    }
                    return "*";
                }
                else return cnChar;
            }  
  • 相关阅读:
    Android系统的Binder机制之一——Service Manager
    Android系统的Binder机制之二——服务代理对象(1)
    电子书
    [ 具体数学 ] 1:递归式与封闭式
    线段树封装
    实验1——顺序表的合并
    配置终端VIM 文件
    编译原理:实验二、集合与线性表操作
    括号匹配检验
    Problem B: KMP算法综合应用余庆
  • 原文地址:https://www.cnblogs.com/nzcblog/p/4239548.html
Copyright © 2011-2022 走看看