首页 > Windows开发 > 详细

C#汉字转十六进制

时间:2015-07-23 09:18:49      阅读:174      评论:0      收藏:0      [点我收藏+]

public class chsHex
{
/// <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;
}

C#汉字转十六进制

原文:http://www.cnblogs.com/IT-haidong/p/4669373.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!