c# 字符串(含有汉字)转化为16进制编码(转)

王朝学院·作者佚名  2016-05-17
窄屏简体版  字體: 小  |  中  |  大  |  超大  

c# 字符串(含有汉字)转化为16进制编码(转) 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转化成十六进制string

}

return result;

}

变成可以在网上传输的那种16进制编码,类似%8D%E2这种?这样的话,

用System.Web.HTTPUtility.URLEncode()就行。

光光10进制转换到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

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航