Asked By
ann tanner
20 points
N/A
Posted on - 04/05/2013
I am getting many problems with vbscript hex encode on my web. I need to fix those errors but I don’t know which code to use and how can I write that. Can anybody provide me the right code or the site where can I get it? Thank you in advance!
How to decide the problem with vbscript hex encode?
Following are the code for hexencode and decode .
Hexencode function precedes the string with % so that it is easily used in the url. Here this hexEncode function expects the input parameter as a string and then convert one by one every character of the string into ASCII and then into hex.
Mid , asc, hex is a built-in vbscript function.
function hexEncode(str)
dim strEncoded, i
strEncoded = ""
for i = 1 to Len(str)
strEncoded = strEncoded + "%" + Hex(Asc(Mid(str, i, 1)))
next
hexEncode = strEncoded
end function
The hexDecode function accepts the encoded string and decodes it to original string. Chr, clang is the built-in vbscript function.
function hexDecode(str)
dim strDecoded, i, hexValue
strDecoded = ""
for i = 2 to Len(str)
hexValue = ""
while Mid(str, i, 1) <> "%" and i <= Len(str)
hexValue = hexValue + Mid(str, i, 1)
i = i+1
wend
strDecoded = strDecoded + chr(CLng("&h" & hexValue)) next
hexDecode = strDecoded
end function
Thanks