博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#根据汉字生成拼音首字母全称
阅读量:4546 次
发布时间:2019-06-08

本文共 1200 字,大约阅读时间需要 4 分钟。

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 }

控制台运行结果为:

转载于:https://www.cnblogs.com/zsmj001/p/4092099.html

你可能感兴趣的文章
个人待办事项工具的设计和搭建(IFE前端2015春季 任务3)
查看>>
nginx
查看>>
openssl生成ssl证书
查看>>
matplotlib 柱状图 Bar Chart 样例及参数
查看>>
The 10th SWJTU Collegiate Programming Contest - Online Round
查看>>
我一路奔来,奔向未来
查看>>
Leangoo敏捷项目协作工具到底好在哪里?
查看>>
运行AVD遇到“Emulator] could not get wglGetExtensionsStringARB”问题的原因
查看>>
iOS:UIImageView图像视图控件
查看>>
iOS:第三方数据库文件FMDB的使用
查看>>
Netron 开源图形控件
查看>>
WPF CommonBox Style
查看>>
检测网络状态
查看>>
原创:VS调试 不会命中断点,源代码与原始版本不同的解决思路
查看>>
20170824xlVBA出车对账单
查看>>
iview,用render函数渲染
查看>>
UVa 129 Krypton Factor【回溯】
查看>>
简单之美—软件开发实践者的思考—故事场景3
查看>>
WPF 资源
查看>>
切记,不要忽略异常
查看>>