Asp url encoding and decoding

Source: Internet
Author: User

URL encoding is an encoding method that must replace characters with special meanings to transmit information through URLs. In ASP, we all know that there is a server. urlencode function can complete this function. That is:
If there are spaces, replace % 20. If there are other characters, replace % ASCII. If there are four characters including Chinese characters, replace them with two % ASCII characters. However, sometimes we also need to decode the encoded string, but ASP does not provide related functions, which brings us some trouble to solve the problem. In fact, as long as we know the encoding rules, we can use ASP code to implement our own urldecode function.
The specific implementation is as follows:
Function urldecode (encodestr) <br/> newstr = "" <br/> havechar = false <br/> lastchar = "" <br/> for I = 1 to Len (encodestr) <br/> char_c = mid (encodestr, I, 1) <br/> If char_c = "+" then <br/> newstr = newstr & "" <br/> elseif char_c = "%" then <br/> next_1_c = mid (encodestr, I + 1, 2) <br/> next_1_num = CINT ("& H" & next_1_c) <br/> If havechar then <br/> havechar = false <br/> newstr = newstr & CHR (CINT ("& H" & lastchar & next_1_c )) <br/> else <br/> If ABS (next_0000num) <= 127 then <br/> newstr = newstr & CHR (next_0000num) <br/> else <br/> havechar = true <br/> lastchar = next_0000c <br/> end if <br/> I = I + 2 <br/> else <br/> newstr = newstr & char_c <br/> end if <br/> next <br/> urldecode = newstr <br/> end function <br />

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.