Chinese character Pinyin and Pinyin Code Acquisition
Public class classime_spell_code
{
Public classime_spell_code ()
{
}
# Region Chinese pinyin code
/// <Summary>
/// Chinese pinyin code
/// </Summary>
Public static string getime_spell (string strimechar)
{
String strresult = "";
Try
{
For (INT I = 0; I <strimechar. length; I ++)
{
Strresult = strresult + extract_hz (strimechar. substring (I, 1 ));
}
Return strresult;
}
Catch (system. nullreferenceexception nullex)
{
Throw nullex;
}
Catch (exception ex)
{
Throw ex;
}
}
// Here is the first letter to obtain pinyin.
Public static string extract_hz (string Hz)
{
Try
{
Byte [] ZW = new byte [2];
Long hz_int;
ZW = system. Text. encoding. Default. getbytes (HZ );
// Get the array of byte from the single char
If (ZW. Length <= 1)
{
Return Hz;
}
Int I1 = (short) (ZW [0]);
Int I2 = (short) (ZW [1]);
Hz_int = I1 * 256 + I2; // expresstion
// Table of the constant list
// 'A'; // 45217 .. 45252
// 'B'; // 45253 .. 45760
// 'C'; // 45761 .. 46317
// 'D'; // 46318 .. 46825
// 'E'; // 46826 .. 47009
// 'F'; // 47010 .. 47296
// 'G'; // 47297 .. 47613
// 'H'; // 47614 .. 48118
// 'J'; // 48119 .. 49061
// 'K'; // 49062 .. 49323
// 'L'; // 49324 .. 49895
// 'M'; // 49896 .. 50370
// 'N'; // 50371 .. 50613
// 'O'; // 50614 .. 50621
// 'P'; // 50622 .. 50905
// 'Q'; // 50906 .. 51386
// 'R'; // 51387 .. 51445
//'S '; // 51446 .. 52217
// 'T'; // 52218 .. 52697
// No u, v
// 'W'; // 52698 .. 52979
// 'X'; // 52980 .. 53640
// 'Y'; // 53689 .. 54480
// 'Z'; // 54481 .. 55289
// Hz_int match the constant
If (hz_int> = 45217) & (hz_int <= 45252 ))
{
Return "";
}
If (hz_int> = 45253) & (hz_int <= 45760 ))
{
Return "B ";
}
If (hz_int> = 45761) & (hz_int <= 46317 ))
{
Return "C ";
}
If (hz_int> = 46318) & (hz_int <= 46825 ))
{
Return "D ";
}
If (hz_int> = 46826) & (hz_int <= 47009 ))
{
Return "E ";
}
If (hz_int> = 47010) & (hz_int <= 47296 ))
{
Return "F ";
}
If (hz_int> = 47297) & (hz_int <= 47613 ))
{
Return "G ";
}
If (hz_int> = 47614) & (hz_int <= 48118 ))
{
Return "H ";
}
If (hz_int> = 48119) & (hz_int <= 49061 ))
{
Return "J ";
}
If (hz_int> = 49062) & (hz_int <= 49323 ))
{
Return "K ";
}
If (hz_int> = 49324) & (hz_int <= 49895 ))
{
Return "L ";
}
If (hz_int> = 49896) & (hz_int <= 50370 ))
{
Return "M ";
}
If (hz_int> = 50371) & (hz_int <= 50613 ))
{
Return "N ";
}
If (hz_int> = 50614) & (hz_int <= 50621 ))
{
Return "O ";
}
If (hz_int> = 50622) & (hz_int <= 50905 ))
{
Return "p ";
}
If (hz_int> = 50906) & (hz_int <= 51386 ))
{
Return "Q ";
}
If (hz_int> = 51387) & (hz_int <= 51445 ))
{
Return "R ";
}
If (hz_int> = 51446) & (hz_int <= 52217 ))
{
Return "S ";
}
If (hz_int> = 52218) & (hz_int <= 52697 ))
{
Return "T ";
}
If (hz_int> = 52698) & (hz_int <= 52979 ))
{
Return "W ";
}
If (hz_int> = 52980) & (hz_int <= 53640 ))
{
Return "X ";
}
If (hz_int> = 53689) & (hz_int <= 54480 ))
{
Return "Y ";
}
If (hz_int> = 54481) & (hz_int <= 55289 ))
{
Return "Z ";
}
Return "";
}
Catch (system. nullreferenceexception nullex)
{
Throw nullex;
}
Catch (exception ex)
{
Throw ex;
}
}
// Obtain Chinese pinyin
Class classime_spell_full
{
Public classime_spell_full ()
{
}
Public const uint ime_regword_style_user_first = 0x80000000;
Private string result, srcstring = "word ";
Public Delegate void mycallback (string lpszreading, uint dwstyle, string lpszstring, object O );
Public mycallback ACC;
[Dllimport ("imm32.dll")]
Public static extern uint immenumregisterword (uint HKL, mycallback lpfnenumproc, string lpszreading, uint dwstyle, string lpszregister, object O );
// Call this to register word
Public void immcall (string [] ARGs)
{
Py = new mycallback (mycbproc );
// Register the callback function. The srcstring stores the Chinese characters to be queried.
Uint x = immenumregisterword (0xe00e0804, Py, null, ime_regword_style_user_first + 1, srcstring, null );
}
// Callback function. Each callback returns a pronunciation of a Chinese character (multiphoneme)
Public void mycbproc (string lpszreading, uint dwstyle, string lpszstring, object O)
{
Result + = lpszreading;
}
}
# Endregion
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 222373