471,318 Members | 3,223 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

How to convert a String into Byte[]

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 : (
Dec 3 '05 #1
5 8831
EOS wrote:
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:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Dec 3 '05 #2
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" <la***@vkarlsen.no> wrote in message
news:uS****************@tk2msftngp13.phx.gbl...
EOS wrote:
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:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2

Dec 4 '05 #3
EOS
By the way, I forgot to mention that it is for compact .NET (PDA)

"EOS" <no****@nospam.org> wrote in message
news:uM****************@TK2MSFTNGP14.phx.gbl...
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" <la***@vkarlsen.no> wrote in message
news:uS****************@tk2msftngp13.phx.gbl...
EOS wrote:
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:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2


Dec 4 '05 #4
EOS <no****@nospam.org> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 4 '05 #5
EOS
It actually jump out from the try loop...

I will try to print out the error codes..

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
EOS <no****@nospam.org> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 5 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Nathan | last post: by
1 post views Thread by Swarup | last post: by
6 posts views Thread by Ricardo Quintanilla | last post: by
6 posts views Thread by Bob Altman | last post: by
12 posts views Thread by Peter | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.