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 += "&#x" + System.Convert.ToString(arrByte[i], 16) + ";"; //Convert.ToString(byte, 16)把byte轉(zhuǎn)化成十六進制string
}
return result;
}
變成可以在網(wǎng)上傳輸?shù)哪欠N16進制編碼,類似%8D%E2這種?這樣的話,
用System.Web.HTTPUtility.URLEncode()就行。
光光10進制轉(zhuǎn)換到16進制的話,可以用 bytes(i).ToString("X"),<PRe style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0
新聞熱點
疑難解答