String to Byte Array

T

Tom

Stupid Question: Have a string ("ABC"); need to convert that to a byte array
(Dim x(3) as Byte). Do I have to do this manually or is there a .NET
command to do it automatically?

Tom
 
T

Tom

Armin: Cool, thanks! However, I had to use
System.Text.Encoding.ASCII.GetBytes to convert it properly - otherwise, I
was getting a NULL (chr(0)) between each character.

Also, I see that System.Text.Encoding.ASCII.GetChars converts it back to a
string value.

Tom
 
H

Herfried K. Wagner [MVP]

* "Tom said:
Also, I see that System.Text.Encoding.ASCII.GetChars converts it back to a
string value.

If you want a string, you can use 'GetString' instead of 'GetChars'.
 
A

Armin Zingler

Tom said:
Armin: Cool, thanks! However, I had to use
System.Text.Encoding.ASCII.GetBytes to convert it properly -
otherwise, I was getting a NULL (chr(0)) between each character.

That's what Unicode encoding means: 2 bytes per character.

ASCII: You know that ASCII is 7 bits only, i.e. no values > 127 possible?
Also, I see that System.Text.Encoding.ASCII.GetChars converts it back
to a string value.

Why not GetString instead of GetChars?
 

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