C # code for converting Chinese characters into pinyin abbreviations,
Using System; using System. configuration; using System. data; using System. web; using System. web. security; using System. web. UI; using System. web. UI. htmlControls; using System. web. UI. webControls; using System. web. UI. webControls. webParts; public partial class _ Default: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {Response. write (GetPYString ("People's Republic of China");} public string GetPYString (string str) {string tempStr = ""; foreach (char c in str) {if (int) c> = 33 & (int) c <= 126) {// The original tempStr + = c. toString ();} else {// accumulate pinyin initials tempStr + = GetPYChar (c. toString () ;}} return tempStr ;} ///// obtain the pinyin initials of a single character ///// the single Chinese character to be converted /// the pinyin initials 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 ""; 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 <0 xCBFA) return "s "; if (I <0 xCDDA) return "t"; if (I <0xCEF4) return "w"; if (I <0xD1B9) return "x"; if (I <0xD4D1) return "y"; if (I <0xD7FA) return "z"; return "*";}}