String from a byte array

J

John Dann

Just wondering about the best way of assembling a string from a byte
array in VB.Net. I have a sequence of Ascii characters read into a
byte array from a binary file and need to reassemble these into their
original string.

I guess I could do something like:

for i as integer = 0 to ubound(byte())
string &= byte(i) (do I need a .tostring)
next

But maybe there's a more direct/approved/elegant method?

If it makes any difference, in this particular example, it's a
relatively short (16 byte string) that will probably only be used once
in the program so there's no great need for efficiency. But I'm asking
more out of interest in the principle as to the best approach.

TIA
John Dann
 
H

Herfried K. Wagner [MVP]

* John Dann said:
Just wondering about the best way of assembling a string from a byte
array in VB.Net. I have a sequence of Ascii characters read into a
byte array from a binary file and need to reassemble these into their
original string.

\\\
Dim s As String = System.Text.Encoding.ASCII.GetString(abyt)
///

For other encodings, play around with the 'ASCII', there are many other
encodings available too.
 

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