public string getpystring (String str)
{
string tempstr = "";
foreach (char c in str)
{
if (int) c >= && (int) c <=126)
{//letters and symbols are preserved
TempStr + + c.tostring ();
}
Else
{//cumulative phonetic initials
TempStr + + Getpychar (c.tostring ());
}
}
return tempstr;
}
<summary>
///The phonetic initials of a single character
///Code by MuseStudio@hotmail.com
///2004-11-30
///</summary>
///<param name= "C" > individual Chinese characters to be converted </param>
///<returns> Pinyin initials </returns>
public string Getpychar (string c)
{
byte[] array = new BYTE[2];
array = System.Text.Encoding.Default.GetBytes (c);
int i = (short) (Array[0]-"') * 256 + ((short) (array[1)-"));
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 "*";
}