如果有空格就用 %20 代替,如果有其它字符就用 %ASCII 代替,如果有汉字等四个字节的字符,就用两个 %ASCII 来代替。不过有时候我们也需要将经过这种编码的字符串进行解码,但 ASP 并没有提供相关的函数,这给我们处理问题带来了一定的麻烦。其实我们只要知道了编码规则后,就可以用 ASP 代码来实现我们自己的 URLDecode 函数了。以下是按 GB2312 来进行解码的:
function URLDecode(enStr)
dim deStr, strSpecial
dim c, i, v
deStr = ""
strSpecial = "!""#$%&'()*+,.-_/:;<=>?@[\]^`{|}~%"
for i = 1 to Len(enStr)
c = Mid(enStr, i, 1)
if c = "%" then
v = eval("&h" + Mid(enStr, i + 1, 2))
if inStr(strSpecial, chr(v)) > 0 then
deStr = deStr & chr(v)
i = i + 2
else
v = eval("&h" + Mid(enStr, i+1, 2) + Mid(enStr, i+4, 2))
deStr = deStr & chr(v)
i = i + 5
end if
else
if c = "+" then
deStr = deStr & " "
else
deStr = deStr & c
end if
end if
next
URLDecode = deStr
end function
相关阅读