/// <Summary>
/// Convert Chinese characters to unicode encoding
/// </Summary>
/// <Param name = "str"> Chinese character string to be encoded </param>
/// <Returns> Unicode-encoded string </returns>
Public static string tounicode (string Str)
{
Byte [] BTS = encoding. Unicode. getbytes (STR );
String r = "";
For (INT I = 0; I <BTS. length; I + = 2) R + = "\ U" + BTS [I + 1]. tostring ("X "). padleft (2, '0') + BTS [I]. tostring ("X "). padleft (2, '0 ');
Return R;
}
/// <Summary>
/// Convert unicode encoding to a Chinese character string
/// </Summary>
/// <Param name = "str"> unicode encoded string </param>
/// <Returns> Chinese character string </returns>
Public static string togb2312 (string Str)
{
String r = "";
Matchcollection MC = RegEx. matches (STR, @ "\ U ([\ W] {2}) ([\ W] {2})", regexoptions. compiled | regexoptions. ignorecase );
Byte [] BTS = new byte [2];
Foreach (Match m in MC)
{
BTS [0] = (byte) int. parse (M. Groups [2]. Value, numberstyles. hexnumber );
BTS [1] = (byte) int. parse (M. Groups [1]. Value, numberstyles. hexnumber );
R + = encoding. Unicode. getstring (BTS );
}
Return R;
}
Convert Unicode to a Chinese character string