How to convert a String into Byte[]

E

EOS

Hi,

Thanks for this great forum and my convertion from Byte[] into String works
beautifully with Encoding.ASCII.GetString()

Anyone how to do the reverse, I mean convert a String into Byte[]?

In C\C++, I will cast the CString into LPCTSTR and use simple memcpy.

By the way, since I am into C# (from background of C\C++), I felt like
complete idiots and hard to do a simple thing : (
 
?

=?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

EOS said:
Hi,

Thanks for this great forum and my convertion from Byte[] into String works
beautifully with Encoding.ASCII.GetString()

Anyone how to do the reverse, I mean convert a String into Byte[]?
<snip>

Replace .GetString with .GetBytes.
 
E

EOS

Hi,

Thanks for the suggestion.

But I found my codes give error after appling;

f_byteParam = Encoding.ASCII.GetBytes(f_szParam);

where f_byteParam is a Byte[] and f_szParam is a String.



Any ideas on where is my mistake?

Lasse Vågsæther Karlsen said:
EOS said:
Hi,

Thanks for this great forum and my convertion from Byte[] into String
works beautifully with Encoding.ASCII.GetString()

Anyone how to do the reverse, I mean convert a String into Byte[]?
<snip>

Replace .GetString with .GetBytes.


--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:[email protected]
PGP KeyID: 0x2A42A1C2
 
E

EOS

By the way, I forgot to mention that it is for compact .NET (PDA)

EOS said:
Hi,

Thanks for the suggestion.

But I found my codes give error after appling;

f_byteParam = Encoding.ASCII.GetBytes(f_szParam);

where f_byteParam is a Byte[] and f_szParam is a String.



Any ideas on where is my mistake?

Lasse Vågsæther Karlsen said:
EOS said:
Hi,

Thanks for this great forum and my convertion from Byte[] into String
works beautifully with Encoding.ASCII.GetString()

Anyone how to do the reverse, I mean convert a String into Byte[]?
<snip>

Replace .GetString with .GetBytes.


--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:[email protected]
PGP KeyID: 0x2A42A1C2
 
J

Jon Skeet [C# MVP]

EOS said:
Thanks for the suggestion.

But I found my codes give error after appling;

f_byteParam = Encoding.ASCII.GetBytes(f_szParam);

where f_byteParam is a Byte[] and f_szParam is a String.

It would help if you could say what error was being given.
 
E

EOS

It actually jump out from the try loop...

I will try to print out the error codes..

Jon Skeet said:
EOS said:
Thanks for the suggestion.

But I found my codes give error after appling;

f_byteParam = Encoding.ASCII.GetBytes(f_szParam);

where f_byteParam is a Byte[] and f_szParam is a String.

It would help if you could say what error was being given.
 

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