赞
踩
string code = "D6 B1 B2 E5 CA BD 32 30 31 39 31 32 32 37 30 30 30 32 31 0D";
string[] codeArr = code.Split(' ');
int codeLen = codeArr.Length;
byte[] codeByteArr = new byte[codeArr.Length];
if (codeLen > 0)
{
for (int i = 0; i < codeLen; i++)
{
codeByteArr[i] = (byte)Convert.ToByte(codeArr[i], 16);
}
}
string res = Encoding.GetEncoding("GBK").GetString(codeByteArr);
//结果:直插式2019122700021\r
string chinese = "汉字哦110";
byte[] gbk = Encoding.GetEncoding("GBK").GetBytes(chinese);
string gbkStr = ""; string byteStr = "";
foreach (byte b in gbk)
{
//s1 += Convert.ToString(b, 16)+" ";
gbkStr += string.Format("{0:X2}", b) + " ";
byteStr += b + " ";
}
//结果:
gbkStr :BA BA D7 D6 C5 B6 31 31 30
byteStr :186 186 215 214 197 182 49 49 48
string code = "D6 B1 B2 E5 CA BD 32 30 31 39 31 32 32 37 30 30 30 32 31 0D";
string[] codeArr = code.Split(' ');
int codeLen = codeArr.Length;
byte[] codeByteArr = new byte[codeArr.Length];
if (codeLen > 0)
{
for (int i = 0; i < codeLen; i++)
{
codeByteArr[i] = (byte)Convert.ToByte(codeArr[i], 16);
}
}
string res = Encoding.GetEncoding("Unicode").GetString(codeByteArr);
//结果:直插式2019122700021\r
string chinese = "汉字哦110";
byte[] uniCode = Encoding.Unicode.GetBytes(chinese);
string uniStr = ""; string uniByte = "";
foreach (byte b in uniCode)
{
//s2 += Convert.ToString(b, 16) + " ";
uniStr += string.Format("{0:X2}", b) + " ";
uniByte += b + " ";
}
//结果:
49 6C 57 5B E6 54 31 00 31 00 30 00
73 108 87 91 230 84 49 0 49 0 48 0
string code = "D6 B1 B2 E5 CA BD 32 30 31 39 31 32 32 37 30 30 30 32 31 0D";
string[] codeArr = code.Split(' ');
int codeLen = codeArr.Length;
byte[] codeByteArr = new byte[codeArr.Length];
if (codeLen > 0)
{
for (int i = 0; i < codeLen; i++)
{
codeByteArr[i] = (byte)Convert.ToByte(codeArr[i], 16);
}
}
string res = Encoding.GetEncoding("UTF-8").GetString(codeByteArr);
//结果:直插式2019122700021\r
string chinese = "汉字哦110";
byte[] uniCode = Encoding.UTF8.GetBytes(chinese);
string uniStr = ""; string uniByte = "";
foreach (byte b in uniCode)
{
//s2 += Convert.ToString(b, 16) + " ";
uniStr += string.Format("{0:X2}", b) + " ";
uniByte += b + " ";
}
//结果:
49 6C 57 5B E6 54 31 00 31 00 30 00
73 108 87 91 230 84 49 0 49 0 48 0
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。