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