Home All Groups Group Topic Archive Search About

converting from TextBox1.Text to Byte()

Author
10 Jan 2006 5:03 PM
Jason
Hi.

Does anyone have a snippet of code that will convert a character string to a
byte array?  I've nearly smashed my head against the wall trying to figure
this out.

I'm Using vb.net 2003

The problem that I am running into is that System.Type.GetType("Byte")
returns null.  Anybody know why?  I've tried code similiar to the following
to achieve my results:

Dim theCommand as New ArrayList
For each c as Char in InputTextBox.Text.ToCharArray()
    theCommand.Add(c)
Next
Dim TempArray as Byte()
TempArray = theCommand.ToArray(System.Type.GetType("Byte"))
' The above line should give me a byte array of the previous text, but
instead it just errors saying that System.Type.GetType("Byte")) is null

Any Ideas?

Thanks in advance,

-- Jason

Author
10 Jan 2006 5:38 PM
Cor Ligthert [MVP]
Jason,

That needs no snippet, the text.encoding class is complete for that.

http://msdn2.microsoft.com/en-us/library/system.text.encoding.getbytes.aspx

I hope this helps,

Cor
Author
10 Jan 2006 5:40 PM
Herfried K. Wagner [MVP]
"Jason" <ja***@acd.net> schrieb:
> Does anyone have a snippet of code that will convert a character string to
> a
> byte array?  I've nearly smashed my head against the wall trying to figure
> this out.

'System.Text.Encoding.<encoding>.GetBytes'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>