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.