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;
            }  
  • 相关阅读:
    matlab 修改窗口logo 使用Javaframe
    matlab guide 开发心得
    判断两个集合的包含关系
    xaml 中 引用嵌套类的对象
    xaml中显示 “大括号左边” 文本
    步进电机脉冲与毫米
    最短路径:Dijkstra算法 C#
    JPA自定义sql的三种方式
    double相乘少一分的问题,BigDecimal参数传小数也会出问题
    String类小知识
  • 原文地址:https://www.cnblogs.com/nzcblog/p/4239548.html
Copyright © 2011-2022 走看看