How convert byte array to string
This question already has an answer here:
取决于您希望使用的编码:
var str = System.Text.Encoding.Default.GetString(result);
假设你正在使用UTF-8编码:
string convert = "This is the string to be converted";
// From string to byte array
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(convert);
// From byte array to string
string s = System.Text.Encoding.UTF8.GetString(buffer, 0, buffer.Length);
您可以在不使用BlockCopy处理编码的情况下执行此操作:
char[] chars = new char[bytes.Length / sizeof(char)];
System.Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
string str = new string(chars);
链接地址: http://www.djcxy.com/p/53670.html
下一篇: 如何将字节数组转换为字符串