汉字转拼音:简单思路方法在C#中取得汉字的拼音的首字母

  今天在yyf9989 Blog 上看到C#计算汉语拼音码 看了里面代码觉得是比较繁琐它主要是检索输入汉字在位置然后返回第个字母于是就想起来了可以利用汉字在计算机里面编码来到汉字首拼音查找了些资料通过以下思路方法成功得到了解决就放在这里请朋友们参考

public GetChineseSpell( strText)
{
len = strText.Length;
myStr = "";
for( i=0;i<len;i)
{
myStr getSpell(strText.Sub(i,1));
}
myStr;
}
public getSpell( cnChar)
{
arrCN = Encoding.Default.GetBytes(cnChar);
(arrCN.Length > 1)
{
area = ()arrCN[0];
pos = ()arrCN[1];
code = (area<<8) + pos;
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( i=0;i<26;i)
{
max = 55290;
(i != 25) max = areacode[i+1];
(areacode[i]<=code && code<max)
{
Encoding.Default.GetString( {()(65+i)});
}
}
"*";
}
cnChar;
}


Tags:  汉字转换拼音 汉字拼音 汉字转拼音

延伸阅读

最新评论

发表评论