The function of Chinese pinyin abbreviation (C #)

Source: Internet
Author: User
Tags tostring
function | Chinese pinyin just finishing up-the function of Chinese pinyin abbreviation (C #)
On the csdn looked for a moment, did not find a complete conversion function, special on the basis of the predecessors to organize a bit, the next project may be used.        Thanks to Bugfree (eight flying). <summary>
Pinyin abbreviation for Chinese character conversion
Code by MuseStudio@hotmail.com
2004-11-30
</summary>
<param name= "str" > character string to be converted </param>
<returns> Pinyin abbreviation </returns>
public string getpystring (String str)
{
String tempstr = "";
foreach (char c in str)
{
if (int) c >= && (int) c <=126)
{//letters and symbols are left intact
TempStr + + c.tostring ();
}
Else
{//Add pinyin Initials
TempStr + + Getpychar (c.tostring ());
}
}
return tempstr;
}///<summary>
Pinyin initials for 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]-' and ') * 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 "*";
}

Related Article

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.