Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

c# - 如何将字节数组转换为字符串[duplicate](How to convert byte array to string [duplicate])

This question already has an answer here:

(这个问题在这里已有答案:)

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 (它不受支持)。)

  ask by Oksana translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

根据您要使用的编码:

var str = System.Text.Encoding.Default.GetString(result);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...