如何字节数组转换为字符串 [英] How convert byte array to string
本文介绍了如何字节数组转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了两个字符串的字节数组。如何转换的字节数组为字符串?
I created a byte array with two strings. How do I convert a byte array to strings?
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);
我想结果
转换为字符串。我可以用做 BinaryReader
。但我不能用 BinaryReader
(不支持)。
I want to convert result
to strings. I can do it using BinaryReader
. But I can not use BinaryReader
(it does not supported).
推荐答案
根据不同的编码要使用:
Depending on the encoding you wish to use:
var str = System.Text.Encoding.Default.GetString(result);
这篇关于如何字节数组转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文