Convert Strings to Byte arrays and back 
Author Message
 Convert Strings to Byte arrays and back

Hello,

I need to convert strings to byte arrays and also byte arrays back to
strings.
Can anyone tell me how to do this or point me to some code.
I've been trying to use ASCIIEncoding.GetBytes  but I can't get it work. I
don't understand
how I need to use it.

Help

Thanks Randy



Fri, 30 Jul 2004 12:52:21 GMT  
 Convert Strings to Byte arrays and back
Hey Randy,

Here is a quick code example I wrote that coverts from a string to byte
array and back.

Dim s As String

Dim b() As Byte

s = "Hello"

b = System.Text.Encoding.Default.GetBytes(s)

s = ""

s = System.Text.Encoding.Default.GetString(b)

MessageBox.Show(s)

I hope this helps,

Brian Bischof, CPA, MCSD, MCT
"The .NET Languages: A Quick Translation Guide"
www.bischofsystems.com/vbnet.asp


Quote:
> Hello,

> I need to convert strings to byte arrays and also byte arrays back to
> strings.
> Can anyone tell me how to do this or point me to some code.
> I've been trying to use ASCIIEncoding.GetBytes  but I can't get it work. I
> don't understand
> how I need to use it.

> Help

> Thanks Randy



Fri, 30 Jul 2004 16:33:45 GMT  
 Convert Strings to Byte arrays and back
Thanks looks prefect:-)

I couldn't figure out how to reference getbytes

Randy


Quote:
> Hey Randy,

> Here is a quick code example I wrote that coverts from a string to byte
> array and back.

> Dim s As String

> Dim b() As Byte

> s = "Hello"

> b = System.Text.Encoding.Default.GetBytes(s)

> s = ""

> s = System.Text.Encoding.Default.GetString(b)

> MessageBox.Show(s)

> I hope this helps,

> Brian Bischof, CPA, MCSD, MCT
> "The .NET Languages: A Quick Translation Guide"
> www.bischofsystems.com/vbnet.asp



> > Hello,

> > I need to convert strings to byte arrays and also byte arrays back to
> > strings.
> > Can anyone tell me how to do this or point me to some code.
> > I've been trying to use ASCIIEncoding.GetBytes  but I can't get it work.
I
> > don't understand
> > how I need to use it.

> > Help

> > Thanks Randy



Fri, 30 Jul 2004 19:43:31 GMT  
 Convert Strings to Byte arrays and back
What I couldn't figure out was to use DEFAULT.
How did you know to use the Default? I couldn't find anything on MSDN
stating that.
Everything I found only showed Encoding.getbytes() which didn't work.

Just trying learn

Randy


Quote:
> Hey Randy,

> Here is a quick code example I wrote that coverts from a string to byte
> array and back.

> Dim s As String

> Dim b() As Byte

> s = "Hello"

> b = System.Text.Encoding.Default.GetBytes(s)

> s = ""

> s = System.Text.Encoding.Default.GetString(b)

> MessageBox.Show(s)

> I hope this helps,

> Brian Bischof, CPA, MCSD, MCT
> "The .NET Languages: A Quick Translation Guide"
> www.bischofsystems.com/vbnet.asp



> > Hello,

> > I need to convert strings to byte arrays and also byte arrays back to
> > strings.
> > Can anyone tell me how to do this or point me to some code.
> > I've been trying to use ASCIIEncoding.GetBytes  but I can't get it work.
I
> > don't understand
> > how I need to use it.

> > Help

> > Thanks Randy



Fri, 30 Jul 2004 19:54:31 GMT  
 Convert Strings to Byte arrays and back
A lot of this stuff in .NET isn't explained well enough in MSDN to
immediately see how something works. I just play around with the different
parts of it and I make mental notes of things as I learn them.
Unfortunately, there's no real science about it.  .NET is so different from
before that it's just going to take time for us to learn all the little
details.  :-)

Take care,

Brian Bischof, CPA, MCSD, MCT
"The .NET Languages: A Quick Translation Guide"
www.bischofsystems.com/vbnet.asp


Quote:
> What I couldn't figure out was to use DEFAULT.
> How did you know to use the Default? I couldn't find anything on MSDN
> stating that.
> Everything I found only showed Encoding.getbytes() which didn't work.

> Just trying learn

> Randy



> > Hey Randy,

> > Here is a quick code example I wrote that coverts from a string to byte
> > array and back.

> > Dim s As String

> > Dim b() As Byte

> > s = "Hello"

> > b = System.Text.Encoding.Default.GetBytes(s)

> > s = ""

> > s = System.Text.Encoding.Default.GetString(b)

> > MessageBox.Show(s)

> > I hope this helps,

> > Brian Bischof, CPA, MCSD, MCT
> > "The .NET Languages: A Quick Translation Guide"
> > www.bischofsystems.com/vbnet.asp



> > > Hello,

> > > I need to convert strings to byte arrays and also byte arrays back to
> > > strings.
> > > Can anyone tell me how to do this or point me to some code.
> > > I've been trying to use ASCIIEncoding.GetBytes  but I can't get it
work.
> I
> > > don't understand
> > > how I need to use it.

> > > Help

> > > Thanks Randy



Sat, 31 Jul 2004 01:02:43 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Converting string array to byte array

2. BinaryRead - howto convert binary string back to string array

3. Convert user defined type or variant to byte array (and back)

4. Need to convert a 16 byte array of bytes to 4 byte integer

5. Converting from string to array of bytes

6. Convert integers and strings to byte array

7. Convert Byte Array to a String

8. Converting between String and Byte Array

9. convert Byte array to string and vice veras

10. Convert a string to byte array

11. Convert an array of bytes to a string

12. StrConv function - Converting a byte array to a string

 

 
Powered by phpBB® Forum Software