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

  • 相关阅读:
    Windows Server 2008 IIS安装FTP及端口配置
    Zabbix 3.4过滤多余的windows网卡监控
    Linux下统计当前文件夹下的文件个数、目录个数
    CentOS 7 使用 ACL 设置文件权限
    Linux服务器CPU使用率较低但负载较高
    Linux下通过 rm -f 删除大量文件时报错:Argument list too long
    nginx环境安装配置fail2ban屏蔽攻击ip
    CentOS 服务器添加简易"回收站"
    游戏行业DDoS攻击解决方案
    使用 fail2ban 防御 SSH 服务器的暴力破解攻击
  • 原文地址:https://www.cnblogs.com/nuaalfm/p/1412077.html
Copyright © 2011-2022 走看看