C # converting Chinese characters into pinyin Functions)

Source: Internet
Author: User

/// <Summary>
/// Convert Chinese characters into pinyin (full spelling)
/// </Summary>
/// <Param name = "hzString"> Chinese character string </param>
/// <Returns> converted pinyin (full spelling) string study.pctoday.net.cn </returns>
Public static string ConvertE (string hzString)
{
// Match Chinese Characters
Regex regex = new Regex ("^ [u4e00-u9fa5] $ ");
Byte [] array = new byte [2];
String pyString = "";
Int chrAsc = 0;
Int i1 = 0;
Int i2 = 0;
Char [] noWChar = hzString. ToCharArray ();

For (int j = 0; j <noWChar. Length; j ++)
{
// Chinese Characters
If (regex. IsMatch (noWChar [j]. ToString ()))
{
Array = System. Text. Encoding. Default. GetBytes (noWChar [j]. ToString ());
I1 = (short) (array [0]);
I2 = (short) (array [1]);
ChrAsc = i1 * 256 + i2-65536;
If (chrAsc> 0 & chrAsc <160)
{
PyString + = noWChar [j];
}
Else
{
// Modify some text
If (chrAsc =-9254) // corrected the word "success ".
PyString + = "Zhen ";
Else
{
For (int I = (pyValue. Length-1); I> = 0; I --)
{
If (pyValue [I] <= chrAsc)
{
PyString + = pyName [I];
Break;
}
}
}
}
}
// Non-Chinese Characters
Else
{
PyString + = noWChar [j]. ToString ();
}
}
Return pyString;
}
# Region converts Chinese characters into pinyin
Private static int [] pyValue = new int []
{
-

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.