How to convert a String into Byte[]

  • Thread starter Thread starter EOS
  • Start date Start date
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 : (
 
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.
 
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
 
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
 
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.
 
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.
 
Back
Top