/// <summary>
/// 汉字转拼音缩写
/// code by musestudio@hotmail.com
/// 2004-11-30
/// </summary>
/// <param name="str">要转换的汉字字符串</param>
/// <returns>拼音缩写</returns>
public string getpystring(string str)
{
string tempstr = "";
foreach(char c in str)
{
if((int)c >= 33 && (int)c <=126)
{//字母和符号原样保留
tempstr += c.tostring();
}
else
{//累加拼音声母
tempstr += getpychar(c.tostring());
}
}
return tempstr;
}
/// <summary>
/// 取单个字符的拼音声母
/// code by musestudio@hotmail.com
/// 2004-11-30
/// </summary>
/// <param name="c">要转换的单个汉字</param>
/// <returns>拼音声母</returns>
public string getpychar(string c)
{
byte[] array = new byte[2];
array = system.text.encoding.default.getbytes(c);
int i = (short)(array[0] - \0) * 256 + ((short)(array[1] - \0));
if ( i < 0xb0a1) return "*";
if ( i < 0xb0c5) return "a";
if ( i < 0xb2c1) return "b";
if ( i < 0xb4ee) return "c";
if ( i < 0xb6ea) return "d";
if ( i < 0xb7a2) return "e";
if ( i < 0xb8c1) return "f";
if ( i < 0xb9fe) return "g";
if ( i < 0xbbf7) return "h";
if ( i < 0xbfa6) return "g";
if ( i < 0xc0ac) return "k";
if ( i < 0xc2e8) return "l";
if ( i < 0xc4c3) return "m";
if ( i < 0xc5b6) return "n";
if ( i < 0xc5be) return "o";
if ( i < 0xc6da) return "p";
if ( i < 0xc8bb) return "q";
if ( i < 0xc8f6) return "r";
if ( i < 0xcbfa) return "s";
if ( i < 0xcdda) return "t";
if ( i < 0xcef4) return "w";
if ( i < 0xd1b9) return "x";
if ( i < 0xd4d1) return "y";
if ( i < 0xd7fa) return "z";
return "*";
}
文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




