Hex to String conversion.

P

Pradeep Kurra

I have a string stored as HEX in my database.
I want to convert it to string.
How can i do that.

Example:
equivalent of "56454849434C4520312057415320494E2054484520"
would be something like "VEHICLE 1 WAS IN THE DRIVE...."

Thanks.
 
A

Armin Zingler

Pradeep Kurra said:
I have a string stored as HEX in my database.
I want to convert it to string.
How can i do that.

Example:
equivalent of "56454849434C4520312057415320494E2054484520"
would be something like "VEHICLE 1 WAS IN THE DRIVE...."

Thanks.

I think you have to convert it manually:

Function AnotherConversion(ByVal s As String) As String
Dim i As Integer
Dim sb As New System.Text.StringBuilder(s.Length \ 2)
For i = 0 To s.Length - 2 Step 2
sb.Append(Chr(Convert.ToByte(s.Substring(i, 2), 16)))
Next
Return sb.ToString
End Function
 
C

Cor

Hi Pradeep,

I think I would do it like this. I never take much time looking for shorter
ones.
But I am not so clever in finding the real short method's for conversion,
so wait a while till you see a beter one and other take this. I tried it and
it works the last word is "the "
\\\\\
Dim a As String = "56454849434C4520312057415320494E2054484520"
Dim b As String = ""
Dim i As Integer
For i = 0 To a.Length - 2 Step 2
b = b & Chr(CInt("&H" & a.Substring(i, 2)))
Next
MessageBox.Show(b)
////

Success
Cor
 
H

Herfried K. Wagner [MVP]

Hello,

Pradeep Kurra said:
I have a string stored as HEX in my database.
I want to convert it to string.
How can i do that.

Example:
equivalent of "56454849434C4520312057415320494E2054484520"
would be something like "VEHICLE 1 WAS IN THE DRIVE...."

Untested:

\\\
Dim s As String = "56454849434C4520312057415320494E2054484520"
Dim t As String, i As Integer
Dim sb As New System.Text.StringBuilder()
For i = 1 To s.Length - 2 Step 2
sb.Append(Convert.ToChar(Convert.ToInt32(Mid(s, i, 2), 16)))
Next i
MsgBox(sb.ToString())
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top