C # code for converting Chinese characters into pinyin abbreviations,

Source: Internet
Author: User

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 "*";}}

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.