vb.net:converting from byte array to string and back again

M

movieknight

Hi,

I have an application that stores raw .wav files (and also
jpgs/bitmaps) within strings, and I need to sometimes convert these
strings to byte arrays, and sometimes go from byte arrays back to
strings.

How do I convert this raw data from one format to another? I don't
think system.text.encoding is useful here as the data is not in any
particular encoding format, it's just raw data and it needs to stay
that way. I have tried system.text.encoding but it stuffs up the raw
data (unless I have chosen the wrong encoding, and I have tried many).

How do I convert from a string to a byte array and back again, without
having to do a for-next loop?

Thanks,

Richard
 
M

movieknight

I tried ASCII, UT7, UT8, UNICODE. The resulting string (from a correct
byte array) is different to the byte array.
 
J

Jon Skeet [C# MVP]

I have an application that stores raw .wav files (and also
jpgs/bitmaps) within strings, and I need to sometimes convert these
strings to byte arrays, and sometimes go from byte arrays back to
strings.

In that case you should use Base64 - use Convert.ToBase64String and
Convert.FromBase64String. Encoding arbitrary binary data as strings
without care is very, very likely to cause you problems later on. Using
Base64 should keep you away from those problems.
 

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