473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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


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

Apr 8 '06 #1
4 3992
Well, what encoding did you choose?
<mo*********@gmail.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...

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

Apr 8 '06 #2

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

Apr 8 '06 #3
<mo*********@gmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 8 '06 #4

Thank you :)

That solved my problems nicely.

Apr 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ross Micheals | last post by:
All I have some general .NET questions that I'm looking for some help with. Some of these questions (like the first) are ones that I've seen various conflicting information on, or questions that...
8
by: Frank R Eid | last post by:
Hi all; A) What's the simplest way to convert a 'String' to 'char *' (and the other way araound) ? B) I have some C++ classes that I cannot easily convert to .NET (because they still are...
0
by: Wayne | last post by:
A field within a FoxPro database typed as a BLOB is reported as s System.String when accessed using Vb.Net. Attempting to fetch the binary data into a .NET string fetches only the first few...
1
by: Metallicraft | last post by:
Is a vb6 byte array the same as a vb.net byte array?
3
by: marfi95 | last post by:
Hi all. I need to copy a byte array into a string, but starting at a specific location in the byte array. This is where I get hung up. For example if my byte array is (100) big, I might want to...
0
by: elavarasar | last post by:
How to use Calendar control in ASP.Net ( Back end Oracle 9i) Please give brief example for understanding.
2
by: MattB | last post by:
Slightly OT, but I know someone must know off the top of their head (and this is for a asp.net application). I have a one dimensional array of a string type that was created using String.Split. I...
1
by: sana krishna | last post by:
How can we take the value of a variable in javascript function to the ASP.NET string I wish to display the value of P using Response.write when I click the Button. //my code <html> <form>...
3
by: eBob.com | last post by:
Is there a regex pattern which will match a VB.Net string? I.E. a regex which matches ... "this is a ""vb.net"" string" (I don't want three matches in this case, I want one.) I've come up...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.