473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 8901
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nathan | last post by:
Is there a way to convert a string to a CipherMessage? I am calling a function that decrypts a CipherMessage and returns the value. The only problem is when I want to use an encrypted value stored...
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
6
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and...
12
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.