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

Hex to String conversion.

P: n/a
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.
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
Hello,

"Pradeep Kurra" <pk****@memphis.edu> schrieb:
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())
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3

P: n/a
"Pradeep Kurra" <pk****@memphis.edu> schrieb
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
--
Armin
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.