HOWTO: convert string to 8-bit bytes and back

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
 
T

Tom Spink

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
 
D

dermot

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
 
H

Herfried K. Wagner [MVP]

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.
 

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