获取汉字的十六进制编码

public static string Str2Hex(string s)
{
string result = string.Empty;

byte[] arrByte = System.Text.Encoding.GetEncoding(“GB2312”).GetBytes(s);
for (int i = 0; i < arrByte.Length; i++)
{
result += “0x” + System.Convert.ToString(arrByte[i], 16).ToUpper() + “,”; //Convert.ToString(byte, 16)把byte转化成十六进制string
}

return result;
}

About

Leave Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.