Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1697
  • Last Modified:

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
0
lmpsteelwire
Asked:
lmpsteelwire
  • 2
  • 2
  • 2
  • +2
1 Solution
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now