zoukankan      html  css  js  c++  java
  • C#中取得汉语拼音首字母

    Code
    static void Main(string[] args)
            {
                Console.WriteLine( GetChineseSpell(
    "笑天下之可笑之人"));  
            }
            
    static public 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;
            }

            
    static public 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)(65 + i) });
                        }
                    }
                    
    return "*";
                }
                
    else return cnChar;
            }

        }

    结果为:

    XTXKXZR

  • 相关阅读:
    项目管理改进实践
    Abount StoneAge Dictionary Project
    词库引擎核心设计
    JDOM / XPATH编程指南
    2007年图灵奖揭晓
    pjscrape: A webscraping framework written in Javascript, using PhantomJS and jQuery
    centos install node.js
    Posts tagged pyqt4
    install python262 写得不错
    WebSPHINX: A Personal, Customizable Web Crawler
  • 原文地址:https://www.cnblogs.com/nuaalfm/p/1412077.html
Copyright © 2011-2022 走看看