473,394 Members | 1,750 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,394 software developers and data experts.

convert a string to a binary

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
4 7771
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Golan | last post by:
Hi, I need to convert a Binary value to Decimal. I've been told that the value is an unsigned one. How can I do this? I use memcpy into an unsigned char variable, but when I print the value I got...
3
by: Petr Jakes | last post by:
Hi, I am trying to convert string to the "escaped string". example: from "0xf" I need "\0xf" I am able to do it like: a="0xf" escaped_a=("\%s" % a ).decode("string_escape") But it looks a...
3
by: Ursula | last post by:
Is it possible to convert a string in a file. The problem is this: I have an object string that is a file xml and I want to pass to Deserialize function, but Deserialize function expect an object...
10
by: steve.lorimer | last post by:
I'm looking for a pre-processor command that will allow me to resolve const strings into const char literals at compile time. Looking at the code below, I can take 5 characters and create a...
5
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I am having a problem converting string to binary and I am hoping someone can help me out I have a sql query that does an update that updates a binary field calles password ...
1
by: svnlakshmi | last post by:
Pls help me out in this aspect--How to convert a binary file to a file in text format using C?
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} ...
9
by: engteng | last post by:
How do I convert string to numeric in VB.NET 2003 ? Example convert P50001 to 50001 or 50001P to 50001 but if P is in middle then not convert. Regards, Tee
0
by: jcarter | last post by:
How can I create a CodeDOM statement to accomplish the following this.pictureBox.Image = <Convert the binary value of the picture from the XML file and display> I have tried the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.