HOWTO: convert string to 8-bit bytes and back

  • Thread starter Thread starter dermot
  • Start date Start date
D

dermot

None of the Converter tyeps (eg ASCIIEncoding )let you
convert between string and 8-bit bytes (0-255).

It took me a long time to find there is a way, well, at
least 2 ways.....here is the way to go fromn string to
bytes....

'Method 1
Dim Enc As Encoding = Encoding.GetEncoding(1252)
Dim pBytes() As Byte = Enc.GetBytes(S)

'Method 2
Dim pBytes() As Byte = Encoding.Default.GetBytes(S)


Dermot Balson
Free VBA code for user interfaces, internet connectivity,
encryption
http://www.webace.com.au/~balson/InsaneExcel/Default.html
Last updated August 2003
 
Hi Dermot,

Are you having a problem with conversion? Also, ASCII is 7-bits, 0-127.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
 
ASCII is 7-Bit

thanks Herfried, that was exactly my problem. I needed 8-
bit conversion which is how the Windows APIs work for VB6.

That's why I posted the sample code, to help others with
the same problem.

regards

Dermot
 
dermot said:
thanks Herfried, that was exactly my problem. I needed 8-
bit conversion which is how the Windows APIs work for VB6.

That's why I posted the sample code, to help others with
the same problem.

No problem, only a little explanation.
 
Back
Top