问题:
This question already has an answer here: 这个问题在这里已有答案:
- How to convert UTF-8 byte[] to string? 如何将UTF-8 byte []转换为字符串? 13 answers 13个答案
I created a byte array with two strings. 我用两个字符串创建了一个字节数组。 How do I convert a byte array to string? 如何将字节数组转换为字符串?
var binWriter = new BinaryWriter(new MemoryStream());
binWriter.Write("value1");
binWriter.Write("value2");
binWriter.Seek(0, SeekOrigin.Begin);
byte[] result = reader.ReadBytes((int)binWriter.BaseStream.Length);
I want to convert result
to a string. 我想将result
转换为字符串。 I could do it using BinaryReader
, but I cannot use BinaryReader
(it is not supported). 我可以使用BinaryReader
,但我不能使用BinaryReader
(它不受支持)。
解决方案:
参考一: https://en.stackoom.com/question/mtso参考二: https://stackoom.com/question/mtso