Converting a byte array into a string;

F

Fabiano

Please,

how can i convert a byte array into an string?

i'm using:

byte[] tmpData = writer.ToArray();ASCIIEncoding tmpXML = new
ASCIIEncoding();

tmpXML.GetString(tmpData);

return tmpXML.ToString();
 
J

Jon Skeet [C# MVP]

Fabiano said:
how can i convert a byte array into an string?

i'm using:

byte[] tmpData = writer.ToArray();ASCIIEncoding tmpXML = new
ASCIIEncoding();

tmpXML.GetString(tmpData);

return tmpXML.ToString();

Well, you'd use

return tmpXML.GetString(tmpData);

Otherwise you're ignoring the result of GetString, and just returning
ASCIIEncoding.ToString.

but a couple of things:

o Is the data *really* just ASCII?
o You don't need to create a new ASCIIEncoding: use the Encoding.ASCII
property instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top