zoukankan      html  css  js  c++  java
  • C#根据汉字生成拼音首字母全称

     1 static void Main(string[] args)
     2 {
     3     string s = GetChineseSpell("周杰伦");
     4     Console.WriteLine(s.ToLower());
     5     Console.ReadKey();
     6 }
     7 static public string GetChineseSpell(string strText)
     8 {
     9     int len = strText.Length;
    10     string myStr = "";
    11     for (int i = 0; i < len; i++)
    12     {
    13     myStr += getSpell(strText.Substring(i, 1));
    14     }
    15     return myStr;
    16 }
    17 
    18 static public string getSpell(string cnChar)
    19 {
    20     byte[] arrCN = Encoding.Default.GetBytes(cnChar);
    21     if (arrCN.Length > 1)
    22     {
    23     int area = (short)arrCN[0];
    24     int pos = (short)arrCN[1];
    25     int code = (area << 8) + pos;
    26     int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 
    27   };
    28 for (int i = 0; i < 26; i++)
    29 {
    30     int max = 55290;
    31     if (i != 25) max = areacode[i + 1];
    32     if (areacode[i] <= code && code < max)
    33     {
    34     return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
    35     }
    36 }
    37 return "*";
    38     }
    39     else return cnChar;
    40 }

    控制台运行结果为:

  • 相关阅读:
    day01
    day02
    Linux安装Redis、PHP安装Redis扩展模块
    数据类型
    Redis常用命令
    Redis高级实用特性
    php操作redis案例
    (转)java二维数组的深度学习(静态与动态)
    java二维数组学习(转)
    java一维数组学习
  • 原文地址:https://www.cnblogs.com/zsmj001/p/4092099.html
Copyright © 2011-2022 走看看