The Code provided in this article is C # code for converting Chinese characters into pinyin abbreviations. It is also a web page development. The specific implementation is as follows:
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Namespace getPageValue
{
Public partial class WebForm1: 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)
{// 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
/// </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]-) * 256 + (short) (array [1]-);
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 "*";
}
}
}