标签:
public string EncodingSMS(string s)
{
string result = string.Empty;
byte[] arrByte = System.Text.Encoding.GetEncoding("GB2312").GetBytes(s);
for(int i = 0; i < arrByte.Length; i++)
{
result += System.Convert.ToString(arrByte[i], 16); //Convert.ToString(byte, 16)把byte转化成十六进制string
}
return result;
}
public string DecodingSMS(string s)
{
string result = string.Empty;
byte[] arrByte = new byte[s.Length / 2];
int index = 0;
for(int i = 0; i < s.Length; i += 2)
{
arrByte[index++] = Convert.ToByte(s.Substring(i,2),16); //Convert.ToByte(string,16)把十六进制string转化成byte
}
result = System.Text.Encoding.Default.GetString(arrByte);
return result;
}
标签:
原文地址:http://www.cnblogs.com/huangzhen22/p/4737517.html