By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

convert a string to a binary

P: n/a
Sam
Hi,
I'm trying to convert a string to a binary format (byte)
I've looked at BitConverter class, but I can't figure out how to use it
for a Strin.
Does anyone know ?

Thx

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Sam,

You can encode a string to a binary array
http://msdn.microsoft.com/library/de...ringtopic.asp\

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
to a byte array

System.Text.Encoding.UTF8.GetBytes(strThestring)

from a byte array to a string

System.Text.Encoding.UTF8.GetString(bytArr)

happy coding

michel [MCP]
"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi,
I'm trying to convert a string to a binary format (byte)
I've looked at BitConverter class, but I can't figure out how to use it
for a Strin.
Does anyone know ?

Thx

Nov 21 '05 #3

P: n/a
"Sam" <sa**************@voila.fr> schrieb:
I'm trying to convert a string to a binary format (byte)
I've looked at BitConverter class, but I can't figure out how to use it
for a Strin.


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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #4

P: n/a
Sam
I've tried this :

row("Password") = System.Text.Encoding.Unicode.GetBytes(txtPwd1.Text )

(row is type System.Byte)

And I get the following exception :

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll

Additional information: System.InvalidCastException: Specified cast is
not valid.
at System.Convert.ToByte(Object value)
at System.Data.Common.ByteStorage.Set(Int32 record, Object value)
at System.Data.DataColumn.set_Item(Int32 record, Object
value)Couldn't store <System.Byte[]> in Password Column. Expected type
is Byte.
What's going on ? Apparentely GetBytes return an array of bytes but it
seems I want just a byte. Actually I'm not so sure about that. In my
database, this field is of type Binaries, so is Byte the right type in
VB ?
Thx

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.