Only urlencode in ASP, no solution to urldecode problem? _ Application Tips

Source: Internet
Author: User
Tags urlencode

When passing parameters in ASP, there is a useful system function Server.URLEncode, you can convert some non-alphanumeric special symbols to the standard URL encoding (in fact, the 16 ASC code), which solves the problem of parameter passing, and then I thought that also provided the Server.urldecode, but after using But found that the program error, the original system did not provide this I imagine the decoding function. Do it yourself.

The principle of urlencode is actually very simple, that is, to convert the special characters into 16 ASC code value, then the decoding function as long as the 16 into the corresponding character of ASC is OK.

function UrlDecode (enstr) ' url decryption function 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 v<128 then DESTR=DESTR&AMP;CHR (v) I=i+2 else if Isvalidhex (Mid (enstr,i,3)) then if Isvalidhex (Mid (enstr,i+3,3)) Then 
           Eval ("&h" +mid (enstr,i+1,2) +mid (enstr,i+4,2)) DESTR=DESTR&AMP;CHR (v) i=i+5 Else V=eval ("&h" +mid (enstr,i+1,2) +cstr (Hex (ASC (Mid (enstr,i+3,1))) DESTR=DESTR&AMP;CHR (v) I 
       =i+3 End If Else destr=destr&c the end if if else if c= "+" then destr=destr& "" Else destr=destr&c End If Next urldecode=destr end Funct Ion function Isvalidhex (str) isvalidhex=true str=ucase (str) if Len (str) <>3 then Isvalidhex=false:exit funct Ion 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

The tested gb312 format is not a problem with ASP usage.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.