由于工作需要,我整理了一个获取汉语声母拼音的帮助类,供大家参考:
使用系统。文本;
命名空间DotNet。公用事业
{
公共课拼音
{
公共静态字符串GetFirstLetter(字符串hz)
{
string ls _ second _ eng = & # 34cjwgnspgcgnesypbtyyyzxykygtdjnnjqmbsgzscyjsyyqpgkbzgygygywjkgkljswkpjqhytwdzlsgmrypywwcckznkydgttngjeykzyktcjnmcyqlypyqfqrpzswbtgkjfyxjzltbncxjjjzxd ttsqzycdxxxhgckbphffsswybgmxlpbyllllhlxszmyjhsojngdzqyklgjhjhsgjhqzhxqgxqgkezzwy+
"hxmjjcjlxqgjmshzkzkwyemylxfsydsglycjqxsjqbsctyhbftdcyzdjwyghqfrxwckqkxebptlpxjzsrmebwhjlbjslydlclqkxlhxjrzjmfqhxwywhtrxxglhqhfnmnykldyxzpwlggt mtcfpajjzyljtyanjjplqgdzyqyaxbkysecjsznslyzhzxlzchpxzhznytdcjkdlz+
"jlyxysyglnscmhcwwmnzjjlxxhchsydsttxrycyxxbyhcxjsznpwgpxxxtaybgajcxxlysdccwzocwccwckccnhcpdyznfcyytyckxkybsqkkytqxfcwchcykelzqbsqyjqcclmthsywhmktlkjlychxwh eqqhthzpqscfymmdmgbwhwlglysdlxmlxpthmjwljzyhzjxhztxjhxhlxwlwzjzxmhzqxszpm+
"sgxfzfcdkhjgxdlqfsgdslqwzkxtmhgzmjzrglypmmlmsxlzjqhzyjczydjwbmjkldpmjegxyhylhxhlqyqhkycwcjmyyxnatjhyccxzpqlbzwwytwbqcmlpmyrcccxfznzzljplxxyztzlg dldcklyrzzzgjhhjjljaxfgjzslcfqzlclgjdjcsnclljpjqdcclcjxzy+
"bbsgghfjlwpmzjnlyyywdqshzxtyywhmcyyywdbdxbbtlmsyyyfsxjcsdxxlhhjhfszcztqcxzxrttdjhnnyzqqmnqdmgyydxmjgdhcdyzffallztdltfxmxqzdngwqdbdczjdxbzgsqqdjc+
"ytdkyxjyycnrjmdjgklclbctbjddbblczqrpxjcglzshltoljnmddlngkaqhqjgykheznmshphqqqjchgmfprxhjgdycghlyrzqlcycyqjnzsqqtkqjymszswlcfqqxyfggyptqwlmcrnfkkfs yylqbmqammmyxctpshcptxxzzphpshmmld qfyqxszyjjjzhhqpdszglstckbxyqzj+
"albxyfbpnlsfhtgjwejjxxglljstgsjqlzfkcgnndszfdeqfhbsaqtgllbxmmygszldydqmjjrgbjtghgkblqkbdmbylxwcxyttybkmrtjzxqhlmhmjzmqasldcyxyqdlqcafywyxqhz & # 34;;
string ls _ second _ ch = & # 34丟19 +
"对不起,对不起,对不起,对不起,对不起。没听说过,也没听说过。+
"对不起,对不起,对不起,对不起。对不起,对不起,对不起,对不起,对不起,对不起,对不起。+
"对不起,对不起,对不起,但是对不起。不要按“不”“不”“不”。+
"我不知道该怎么办,但我不知道该怎么办。郑老,李老,李伟,李伟,李伟,李伟,李伟,李伟,李伟,李伟,李伟。+
"你帮不了自己,但你也帮不了自己。这是个美丽的地方,而且是个美丽的地方。+
"我出生已经很久了。吴的妻子、父亲、母亲、寡妇夫妻一直生活在一起。+
"我不确定我想要什么,但我不确定我想要什么。・・・・・・・・・・・・・・・・・・・・・・・・・12 +
"ㆷㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹㆹ12 ♫♫♫♫♪♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫♫983 +
"看一眼城镇,城镇,城镇,城镇,城镇,城镇,城镇,城镇,城镇,城镇,城镇。+
"李,锆,李,李,锆,如,李,李,李,李,锆,李,李,李,李,锆,李,李,李。脓疱、痂、痣、癫痫、疖、痿、瘀、疖、疖。+
"我不知道该怎么办,但我不知道该怎么办。这是件大事。这是件大事。+
"羧基羰基籼米,糯米,糯米,糯米,糯米对不起,我不知道我有没有麻烦,但是我有麻烦了。+
"鳕鱼,鳗鱼,鲳鱼,鳗鱼,鳟鱼,鲱鱼,半腰斩,鞑靼,鞑靼,鞑靼,鞑靼和鞑靼。;
string return _ py = & # 34";
byte[] array =新字节[2];
for(int I = 0;我& lt赫兹。长度;i++)
{
数组=系统。text . encoding . default . getbytes(Hz[I].ToString());
//非中文字符
if(array[0]& lt;176)
{
return _ py+= Hz[I];
}
//一级汉字
else if(array[0]& gt;= 176 & & array[0]& lt;= 215)
{
if (hz[i].ToString()。compare to(& # 34;转& # 34;)& gt= 0)
return _ py+= & # 34;z & # 34;
else if (hz[i].ToString()。compare to(& # 34;压力& # 34;)& gt= 0)
return _ py+= & # 34;y & # 34;
else if (hz[i].ToString()。compare to(& # 34;昨天& # 34;)& gt= 0)
return _ py+= & # 34;x & # 34;
else if (hz[i].ToString()。compare to(& # 34;哇& # 34;)& gt= 0)
return _ py+= & # 34;w & # 34;
else if (hz[i].ToString()。compare to(& # 34;崩溃& # 34;)& gt= 0)
return _ py+= & # 34;t & # 34;
else if (hz[i].ToString()。compare to(& # 34;萨& # 34;)& gt= 0)
return _ py+= & # 34;s & # 34;
else if (hz[i].ToString()。compare to(& # 34;然而& # 34;)& gt= 0)
return _ py+= & # 34;r & # 34;
else if (hz[i].ToString()。compare to(& # 34;句号& # 34;)& gt= 0)
return _ py+= & # 34;q & # 34;
else if (hz[i].ToString()。compare to(& # 34;Pa & # 34)& gt= 0)
return _ py+= & # 34;p & # 34;
else if (hz[i].ToString()。compare to(& # 34;哦& # 34;)& gt= 0)
return _ py+= & # 34;o & # 34;
else if (hz[i].ToString()。compare to(& # 34;拿& # 34;)& gt= 0)
return _ py+= & # 34;n & # 34;
else if (hz[i].ToString()。compare to(& # 34;妈妈& # 34;)& gt= 0)
return _ py+= & # 34;m & # 34;
else if (hz[i].ToString()。compare to(& # 34;拉& # 34;)& gt= 0)
return _ py+= & # 34;l & # 34;
else if (hz[i].ToString()。compare to(& # 34;Ka & # 34)& gt= 0)
return _ py+= & # 34;k & # 34;
else if (hz[i].ToString()。compare to(& # 34;罢工& # 34;)& gt= 0)
return _ py+= & # 34;j & # 34;
else if (hz[i].ToString()。compare to(& # 34;哈& # 34;)& gt= 0)
return _ py+= & # 34;h & # 34;
else if (hz[i].ToString()。compare to(& # 34;嘎& # 34;)& gt= 0)
return _ py+= & # 34;g & # 34;
else if (hz[i].ToString()。compare to(& # 34;发送& # 34;)& gt= 0)
return _ py+= & # 34;f & # 34;
else if (hz[i].ToString()。compare to(& # 34;母亲& # 34;)& gt= 0)
return _ py+= & # 34;e & # 34;
else if (hz[i].ToString()。compare to(& # 34;拿& # 34;)& gt= 0)
return _ py+= & # 34;d & # 34;
else if (hz[i].ToString()。compare to(& # 34;擦& # 34;)& gt= 0)
return _ py+= & # 34;c & # 34;
else if (hz[i].ToString()。compare to(& # 34;巴& # 34;)& gt= 0)
return _ py+= & # 34;b & # 34;
else if (hz[i].ToString()。compare to(& # 34;啊& # 34;)& gt= 0)
return _ py+= & # 34;一& # 34;;
}
//次要汉字
else if(array[0]& gt;= 215)
{
return_py += ls_second_eng。子串(ls_second_ch。IndexOf(hz[i])。ToString(),0),1);
}
}
返回return_py。ToUpper();
}
///& lt;总结& gt
///取汉语拼音的首字母
///& lt;/summary & gt;
///& lt;param name = & # 34UnName & # 34& gt中文字符</param & gt;
///& lt;returns & gt最初的
公共静态字符串GetCodstring(string UnName)
{
int I = 0;
ushort key = 0;
string strResult = string。空的;
编码unicode =编码。Unicode
编码gbk =编码。get encoding(936);
byte[] unicodeBytes = unicode。GetBytes(un name);
byte[] gbkBytes =编码。Convert(unicode,gbk,unicode bytes);
while(我& lt千兆字节。长度)
{
if(gbk bytes[I]& lt;= 127)
{
strResult = strResult+(char)gbk bytes[I];
i++;
}
#region生成简体中文拼音码,并取拼音首字母。
其他
{
key =(ushort)(gbk bytes[I]* 256+gbk bytes[I+1]);
if(key & gt;= '\ uB0A1 & # 39& & key & lt= '\ uB0C4 & # 39)
{
str result = str result+& # 34;一& # 34;;
}
else if(key & gt;= '\ uB0C5 & # 39& & key & lt= '\ uB2C0 & # 39)
{
str result = str result+& # 34;B&第34名;;
}
else if(key & gt;= '\ uB2C1 & # 39& & key & lt= '\ uB4ED & # 39)
{
str result = str result+& # 34;C & # 34;
}
else if(key & gt;= '\ uB4EE & # 39& & key & lt= '\ uB6E9 & # 39)
{
str result = str result+& # 34;D & # 34;
}
else if(key & gt;= '\ uB6EA & # 39& & key & lt= '\ uB7A1 & # 39)
{
str result = str result+& # 34;E & # 34;
}
else if(key & gt;= '\ uB7A2 & # 39& & key & lt= '\ uB8C0 & # 39)
{
str result = str result+& # 34;F & # 34;
}
else if(key & gt;= '\ uB8C1 & # 39& & key & lt= '\ uB9FD & # 39)
{
str result = str result+& # 34;G & # 34;
}
else if(key & gt;= '\ uB9FE & # 39& & key & lt= '\ uBBF6 & # 39)
{
str result = str result+& # 34;H & # 34;
}
else if(key & gt;= '\ uBBF7 & # 39& & key & lt= '\ uBFA5 & # 39)
{
str result = str result+& # 34;J & # 34;
}
else if(key & gt;= '\ uBFA6 & # 39& & key & lt= '\ uC0AB & # 39)
{
str result = str result+& # 34;K & # 34;
}
else if(key & gt;= '\ uC0AC & # 39& & key & lt= '\ uC2E7 & # 39)
{
str result = str result+& # 34;L & # 34;
}
else if(key & gt;= '\ uC2E8 & # 39& & key & lt= '\ uC4C2 & # 39)
{
str result = str result+& # 34;M & # 34;
}
else if(key & gt;= '\ uC4C3 & # 39& & key & lt= '\ uC5B5 & # 39)
{
str result = str result+& # 34;N & # 34;
}
else if(key & gt;= '\ uC5B6 & # 39& & key & lt= '\ uC5BD & # 39)
{
str result = str result+& # 34;O & # 34;
}
else if(key & gt;= '\ uC5BE & # 39& & key & lt= '\ uC6D9 & # 39)
{
str result = str result+& # 34;P & # 34;
}
else if(key & gt;= '\ uC6DA & # 39& & key & lt= '\ uC8BA & # 39)
{
str result = str result+& # 34;Q & # 34;
}
else if(key & gt;= '\ uC8BB & # 39& & key & lt= '\ uC8F5 & # 39)
{
str result = str result+& # 34;R & # 34;
}
else if(key & gt;= '\ uC8F6 & # 39& & key & lt= '\ uCBF9 & # 39)
{
str result = str result+& # 34;S & # 34;
}
else if(key & gt;= '\ uCBFA & # 39& & key & lt= '\ uCDD9 & # 39)
{
str result = str result+& # 34;T & # 34;
}
else if(key & gt;= '\ uCDDA & # 39& & key & lt= '\ uCEF3 & # 39)
{
str result = str result+& # 34;W & # 34;
}
else if(key & gt;= '\ uCEF4 & # 39& & key & lt= '\ uD188 & # 39)
{
str result = str result+& # 34;X & # 34;
}
else if(key & gt;= '\ uD1B9 & # 39& & key & lt= '\ uD4D0 & # 39)
{
str result = str result+& # 34;Y & # 34;
}
else if(key & gt;= '\ uD4D1 & # 39& & key & lt= '\ uD7F9 & # 39)
{
str result = str result+& # 34;Z & # 34;
}
其他
{
str result = str result+& # 34;?";
}
I = I+2;
}
#结束区域
}
返回strResult
}
}
}