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 />