String to Byte Array

  • Thread starter Thread starter Tom
  • Start date Start date
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
 
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
 
* "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'.
 
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?
 
Back
Top