/// <summary>
/// 從漢字轉換到16進制
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string GetHexFromChs(string s)
{
if ((s.Length % 2) != 0)
{
s += " ";//空格
//throw new ArgumentException("s is not valid chinese string!");
}
System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312");
byte[] bytes = chs.GetBytes(s);
string str = "";
for (int i = 0; i < bytes.Length; i++)
{
str += string.Format("{0:X}", bytes[i]);
}
return str;
}
/// <summary>
/// 從16進制轉換成漢字
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
public static string GetChsFromHex(string hex)
{
if (hex == null)
throw new ArgumentNullException("hex");
if (hex.Length % 2 != 0)
{
hex += "20"