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. the 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, we only need to know the encoding rules, you can use ASP Code To implement our own urldecode function.
The specific implementation is as follows:
Copy code The Code is as follows: function urldecode (encodestr)
Newstr = ""
Havechar = false
Lastchar = ""
For I = 1 to Len (encodestr)
Char_c = mid (encodestr, I, 1)
If char_c = "+" then
Newstr = newstr &""
Elseif char_c = "%" then
Next_shortc = mid (encodestr, I + 1, 2)
Next_1_num = CINT ("& H" & next_1_c)
If havechar then
Havechar = false
Newstr = newstr & CHR (CINT ("& H" & lastchar & next_0000c ))
Else
If ABS (next_1_num) <= 127 then
Newstr = newstr & CHR (next_1_num)
Else
Havechar = true
Lastchar = next_0000c
End if
End if
I = I + 2
Else
Newstr = newstr & char_c
End if
Next
Urldecode = newstr
End Function