convert string to hex or char to hex

tryin to convert a string to hexidecimal....or if i cant do that, convert a char array. thanx
LVL 2
lmpsteelwireIT / Business AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Timbo87Commented:
Converting to a char array is simple.

Dim s As String = "Hello World"
Dim x As Char() = s.ToCharArray()

I don't know if there is a way to convert a whole string to hex, but you can loop through the character array and convert the integer values of the characters.
0
Timbo87Commented:
Convert to hex using escaped characters:

Dim s As String = "Hello World"
Dim x As Char() = s.ToCharArray()
Dim i As Integer = 0
For i = 0 To x.Length - 1
    Console.Write("%{0:x2}", AscW(x(i)))
Next

Convert to hex using non-escaped characters:

Dim s As String = "Hello World"
Dim x As Char() = s.ToCharArray()
Dim i As Integer = 0
For i = 0 To x.Length - 1
    Console.Write("{0:x2}", AscW(x(i)))
Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
Convert a string into hexadecimal means convert it to a byte array I think. This can be done very easy with:

System.Text.ASCIIEncoding.ASCII.GetBytes(<stringToConvert>)

This method returns a byte array.

SoMoS
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Bob LearnedCommented:
Hex() function

Bob
0
Ignacio Soler GarciaSolution Architech & Technical LeadCommented:
The Hex function does the opposite thing. Converts an hexadecimal value to a String representation of the value

SoMoS
0
bladefistCommented:
timbo, what your doing is what im looking for, only you print it into a console window. instead i would rather form a string of the 2-"digit"-value hex

for example, a string "expertsexchange" i want to return the value '6578706572747365786368616e6765'

which is just hex...but that arg0 in console is what is allowing me to format the text
0
lmpsteelwireIT / Business AnalystAuthor Commented:
that last comment is me...Sorry.
0
lmpsteelwireIT / Business AnalystAuthor Commented:
I figured it out using StringBuilder and appendformat
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.