c#获取汉字的拼音首字母

简介:
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 = {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};
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;
}

调用方法例子:textBox3.Text=GetChineseSpell(textBox2.Text); 




     本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/819901,如需转载请自行联系原作者

相关文章
C# 获取汉字拼音首字母
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来。 十年河东十年河西,莫欺少年穷 学无止境,精益求精   本节探讨C#获取汉字拼音首字母的方法: 代码类东西,直接上代码: /// /// 在指定的字符串列表CnStr中检...
3201 0
|
C# 数据格式 JSON
C#序列化的时候将实体进行驼峰命名(第一个首字母小写)
引用的程序集: NewtonSoft 第一种:使用对象的字段属性设置JsonProperty来实现(不推荐,因为需要手动的修改每个字段的属性) public class UserInfo { [JsonProperty("id")] pub...
2346 0
|
C#
C# 汉字转拼音 使用微软的Visual Studio International Pack 类库提取汉字拼音首字母
代码参考该文http://www.cnblogs.com/yazdao/archive/2011/06/04/2072488.html VS2015版本 1.使用Nuget 安装 "SimplifiedChinesePinYinConversion" 2.
1665 0
|
C#
C#取得汉字的拼音的首字母
static public string GetChineseSpell( string strText ){    int len = strText.Length;    string myStr = "";    for( int i=0;i 1 )    {        int area...
1074 0
|
1月前
|
C#
24. C# 编程:用户设定敌人初始血值的实现
24. C# 编程:用户设定敌人初始血值的实现
18 0
|
2月前
|
SQL 数据库连接 应用服务中间件
C#WinForm基础编程(三)
C#WinForm基础编程
71 0
|
2月前
C#WinForm基础编程(二)
C#WinForm基础编程
55 0