• 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;
            }  
  • 相关阅读:
    2017年总结
    计算机基础之进制转换详解
    随机总数字里面选取随机数字进行随机排序案例(JAVA实现)
    XML学习入门
    位运算从入门到入狱第一弹----原创!
    MYSQL数据库引擎区别详解
    时间戳
    数据库三大范式整理
    数组
    JS全选与不选、反选
  • 原文地址:https://www.cnblogs.com/nzcblog/p/4239548.html
Copyright © 2020-2023  润新知