[thelist] Hex to Decimal (Was: ASP URLDecode)

Howard Cheng howcheng at ix.netcom.com
Fri May 3 12:34:12 CDT 2002


OK, combined with Greg's code, then we'd have something like:

Function CharFromHex(myHex)
     myHex = "&H" & myHex
     Dim myInt, myChar
     myInt = CInt(myHex)
     myChar = Chr(myInt)
     CharFromHex = myChar
End Function

Dim re
re = New RegExp
re.Pattern = "%(..)"
re.Global = True

myURL = "http%3A//"
myURL = re.Replace(myURL, CharFromHex("$1"))

See if that works for you.

At 11:18 AM 5/3/2002 -0600, Cymbala, Greg wrote:

>How about this, which takes a character, converts it to hex, then back to a
>character ...
>
>Dim vHexNum, iInteger, vChar
>
>vChar = "W"
>
>iInteger = Asc(vChar)
>
>vHexNum = "&H" & Hex(iInteger)
>Response.Write ("<p>vHexNum = " & vHexNum & "</p>")
>
>iInteger = CInt(vHexNum)
>Response.Write ("<p>iInteger = " & iInteger & "</p>")
>
>vChar = Chr(iInteger)
>Response.Write ("<p>vChar = " & vChar & "</p>")
>
>
>VBScript understangs things prefixed by "&H" to be hexadecimal numbers:
>
>"You can represent hexadecimal numbers directly by preceding numbers in the
>proper range with &H. For example, &H10 represents decimal 16 in hexadecimal
>notation."
>
>If all you've got is a string that you know is a hex number like "3F", just
>previx it with "&H" and do a CInt (or whatever numeric conversion you want)
>on it.
>
>Greg

::::::::::::::::::::::
Howard Cheng
howcheng at ix.netcom.com
AIM: bennyphoebe
ICQ: 47319315




More information about the thelist mailing list