This article mainly introduces the solution to the problem of only UrlEncode in ASP and no Urldecode? , if you need it, please refer to it
There is a very useful system function Server.UrlEncode when passing parameters in ASP. It can convert some special symbols of non-alphanumeric numbers into standard URL encoding (actually hexadecimal ASC code), which solves the parameter passing problem. I thought Server.UrlDecode was also provided, but after using it, I found that the program reported an error. It turned out that the system did not provide this decoding function as I imagined. What to do, do it yourself.
The principle of UrlEncode is actually very simple. It is to convert special characters into hexadecimal ASC code value, so the decoding function just needs to convert hexadecimal ASC back to the corresponding character and it will be OK.
- FunctionURLDecode(enStr)'URL decoding function
- dimdeStr
- dimc,i,v
- deStr=
- fori=1tolen(enStr)
- c=Mid(enStr,i,1)
- ifc=%then
- v=eval(&h+Mid(enStr,i+1,2))
- ifv<128then
- deStr=deStr&chr(v)
- i=i+2
- else
- ifisvalidhex(mid(enstr,i,3))then
- ifisvalidhex(mid(enstr,i+3,3))then
- v=eval(&h+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
- deStr=deStr&chr(v)
- i=i+5
- else
- v=eval(&h+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))))))))
- deStr=deStr&chr(v)
- i=i+3
- endif
- else
- destr=destr&c
- endif
- endif
- else
- ifc=+then
- deStr=deStr&
- else
- deStr=deStr&c
- endif
- endif
- next
- URLDecode=deStr
- endfunction
- functionisvalidhex(str)
- isvalidhex=true
- str=ucase(str)
- iflen(str)<>3thenisvalidhex=false:exitfunction
- ifleft(str,1)<>%thenisvalidhex=false:exitfunction
- c=mid(str,2,1)
- ifnot(((c>=0)and(c<=9))or((c>=A)and(c<=Z)))thenisvalidhex=false:exitfunction
- c=mid(str,3,1)
- ifnot(((c>=0)and(c<=9))or((c>=A)and(c<=Z)))thenisvalidhex=false:exitfunction
- endfunction
There is no problem with using asp in gb312 format after testing.