试试public static byte[] StringToByte(string InString)
{
byte[] ByteOut;
ByteOut = new byte[InString.Length];
for (int i = 0;i< ByteOut.Length;i++)
{
ByteOut[i] = Convert.ToByte(("0x" + InString[i]),16);
}
return ByteOut;
}
{
byte[] ByteOut;
ByteOut = new byte[InString.Length];
for (int i = 0;i< ByteOut.Length;i++)
{
ByteOut[i] = Convert.ToByte(("0x" + InString[i]),16);
}
return ByteOut;
}
可以这样做:
System.Text.UnicodeEncoding encode=new System.Text.UnicodeEncoding();
Byte[] bytes=encode.GetBytes(str);
return bytes;
搞定