Functions for converting Chinese characters to PinYin abbreviations (C #)

Source: Internet
Author: User

Just sorted out-functions for converting Chinese characters to PinYin abbreviations (C #)
I found it on csdn and did not find a complete conversion function. I have sorted it out on the basis of my predecessors. The following projects may be used. Thanks to bugfree ).

/// <Summary>
/// Abbreviated Chinese character to PinYin
// Code by MuseStudio@hotmail.com
/// 2004-11-30
/// </Summary>
/// <Param name = "str"> string of Chinese characters to be converted </param>
/// <Returns> pinyin abbreviation </returns>
Public String getpystring (string Str)
{
String tempstr = "";
Foreach (char C in Str)
{
If (INT) C >=33 & (INT) C <= 126)
{// Reserved letters and symbols
Tempstr + = C. tostring ();
}
Else
{// Accumulate the pinyin initials
Tempstr + = getpychar (C. tostring ());
}
}
Return tempstr;
}

/// <Summary>
/// Obtain the pinyin initials of a single character
// Code by MuseStudio@hotmail.com
/// 2004-11-30
/// </Summary>
/// <Param name = "C"> single Chinese character 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]-'\ 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 "*";
}

 

Copyright Disclaimer: csdn is the hosting service provider of this blog. If this article involves copyright issues, csdn does not assume relevant responsibilities, ask the copyright owner to directlyArticleContact the author.

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.