110,925
社区成员
发帖
与我相关
我的任务
分享
/// 16进制转换成字符串
public static string HexStringToString(string hs)
{
//以%分割字符串,并去掉空字符
string[] chars = hs.Split(new char[] { '%' }, StringSplitOptions.RemoveEmptyEntries);
byte[] b = new byte[chars.Length];
//逐个字符变为16进制字节数据
for (int i = 0; i < chars.Length; i++)
{
b[i] = Convert.ToByte(chars[i], 16);
}
//按照指定编码将字节数组变为字符串
return Encoding.Default.GetString(b, 0, b.Length);
}
public static string HexStringToString(string hs)
{
//以%分割字符串,并去掉空字符
string[] chars = hs.Split(new char[] { '%' });
List<string> newchars = new List<string>();
for (int j = 1; j < chars.Length; j++)
{
if (chars[j] != "")
{
newchars.Add(chars[j]);
}
}
byte[] b = new byte[newchars.Count];
//逐个字符变为16进制字节数据
for (int i = 0; i < newchars.Count; i++)
{
b[i] = Convert.ToByte(newchars[i], 16);
// MessageBox.Show(newchars[i]);
}
//按照指定编码将字节数组变为字符串
return Encoding.GetEncoding("GB2312").GetString(b, 0, b.Length);
}