Public class ChineseCode
{
Protected string _ CnTxt;
Protected string _ EnTxt;
///
/// Chinese characters for letters
///
Public string CnTxt
{
Get {return _ CnTxt ;}
Set {_ CnTxt = value ;}
}
///
/// The first letter of a Chinese character
///
Public string EnTxt
{
Get {return _ EnTxt ;}
Set {_ EnTxt = value ;}
}
///
/// Constructor
///
Public ChineseCode ()
{
}
///
/// Constructor
///
///
Public ChineseCode (string txt)
{
_ CnTxt = txt;
_ EnTxt = IndexCode (_ CnTxt );
}
/// <Summary>
/// Obtain the first letter of a Chinese character
/// </Summary>
/// <Param name = "IndexTxt"> Chinese characters </param>
/// <Returns> first letter of a Chinese character </returns>
Public String IndexCode (String IndexTxt)
{
String _ Temp = null;
For (int I = 0; I <IndexTxt. Length; I ++)
_ Temp = _ Temp + GetOneIndex (IndexTxt. Substring (I, 1 ));
Return _ Temp;
}
/// <Summary>
/// Single Chinese Character
/// </Summary>
/// <Param name = "OneIndexTxt"> Chinese Character </param>
/// <Returns> first fight </returns>
Private String GetOneIndex (String OneIndexTxt)
{
If (Convert. ToChar (OneIndexTxt)> = 0 & Convert. ToChar (OneIndexTxt) <256)
Return OneIndexTxt;
Else
{
Encoding gb2312 = Encoding. GetEncoding ("gb2312 ");
Byte [] unicodeBytes = Encoding. Unicode. GetBytes (OneIndexTxt );
Byte [] gb2312Bytes = Encoding. Convert (Encoding. Unicode, gb2312, unicodeBytes );
Return GetX (Convert. ToInt32 (
String. Format ("{0: D2}", Convert. ToInt16 (gb2312Bytes [0])-160)
+ String. Format ("{0: D2}", Convert. ToInt16 (gb2312Bytes [1])-160)
));
}
}
/// <Summary>
/// Obtain the first letter Based on the location
/// </Summary>
/// <Param name = "GBCode"> location </param>
/// <Returns> initial letter </returns>
Private String GetX (int GBCode)
{
If (GBCode> = 1601 & GBCode <1637) return "";
If (GBCode> = 1637 & GBCode <1833) return "B ";
If (GBCode> = 1833 & GBCode <2078) return "C ";
If (GBCode> = 2078 & GBCode <2274) return "D ";
If (GBCode> = 2274 & GBCode <2302) return "E ";
If (GBCode> = 2302 & GBCode <2433) return "F ";
If (GBCode> = 2433 & GBCode <2594) return "G ";
If (GBCode> = 2594 & GBCode <2787) return "H ";
If (GBCode> = 2787 & GBCode <3106) return "J ";
If (GBCode> = 3106 & GBCode <3212) return "K ";
If (GBCode> = 3212 & GBCode <3472) return "L ";
If (GBCode> = 3472 & GBCode <3635) return "M ";
If