在ASP中傳遞參數時有一個很有用的系統函數Server.UrlEncode,可以將一些非字母數字的特殊符號轉換成標準URL編碼(其實就是16進制ASC碼),這樣就解決了參數傳遞問題,然后我以為也提供了Server.UrlDecode,但使用后卻發現程序報錯,原來系統并沒有提供這個我想象中的解碼函數。怎幺辦,自己動手吧。
Function URLDecode(enStr) 'URL解碼函數
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("h"+Mid(enStr,i+1,2))
if v128 then
deStr=deStrchr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStrchr(v)
i=i+5
else
v=eval("h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStrchr(v)
i=i+3
end if
else
destr=destrc
end if
end if
else
if c="+" then
deStr=deStr" "
else
deStr=deStrc
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)>3 then isvalidhex=false:exit function
if left(str,1)>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c="9")) or ((c>="A") and (c="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c="9")) or ((c>="A") and (c="Z"))) then isvalidhex=false:exit function
end function