Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting hex to string

Status
Not open for further replies.

Proqrammer

Programmer
Sep 17, 2006
64
Hi there

I have this string which is in hex = "20202020202042534433313035454c4a47524259"

I want it to be conveted to ANSI characters which is
" SB3D01E5JLRGYB", is there any built in function to do it?


 
Hi,

I've check google for sample code or hint to know of a built-in function but I've only found a so-so VB6 sample.

I've transformed it to a better vb.net sample, here you go:

Code:
'declare it as public/shared/friend/protected .. you get the point

    Private Function hex2ascii(ByVal HexString As String) As String

        Dim ar() As Char = HexString.ToCharArray
        Dim sb As New System.Text.StringBuilder

        For i As Integer = 0 To ar.GetUpperBound(0) Step 2
            sb.Append(Chr(Val("&h" & ar(i) & ar(i + 1))))
        Next

        Return sb.ToString

    End Function

hope it suits your requirement! [pipe]

---
If gray hair is a sign of wisdom, then talk like a pirate ninja monkey if you get the time to get funky once a week.
Wo bu zhi dao !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top