[thelist] ASP URLDecode

Chris Marsh chrism at puffofsmoke.net
Fri May 3 11:57:00 CDT 2002


> I haven't written one specifically in VBScript, but I have it in Perl:
>
> $url = "http%3A//";
> $url =~ s/%(..)/chr(hex($1))/ge;
>
> So it shouldn't be too hard to convert. Unfortunately Hex() in
VBScript
> converts a base 10 number to hexadecimal, and I can't find a function
> that  does the reverse.

This *should* do it, although someone else can probably write it better:

Function HexToDec(strHex)
	Dim strHexValues
	strHexValues = "0123456789ABCDEF"
	Dim count, i, DecNum, tNum, intDec
	count = Len(strHex)-1
	For i = 0 To count
		tNum = Mid(strHex, Len(strHex))
		strHex = Mid(strHex, 1, Len(strHex)-1)
		intDec = (InStr(1,strHexValues,tNum) - 1) * (16 ^ i)
		DecNum = DecNum + intDec
	Next
	HexToDec = DecNum
End Function

[..]

HTH

Chris Marsh




More information about the thelist mailing list