URL encoding means that in order to transfer information through the URL, some characters that have special meanings must be replaced by a coding method, in the ASP we all know that there is a server.urlencode function to complete this function. That
If there are spaces to replace with%20, if there are other characters to replace with%ASCII, if there are characters such as four bytes of character, the use of two%ascii to replace. But sometimes we also need to decode this encoded string, but the ASP does not provide related functions, which gives us some trouble dealing with the problem. In fact, as long as we know the coding rules, we can use the ASP code to implement our own UrlDecode function.
Specifically implemented as follows:
Copy Code code 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_1_c=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_1_c))
Else
If ABS (next_1_num) <=127 Then
Newstr=newstr & Chr (next_1_num)
Else
Havechar=true
Lastchar=next_1_c
End If
End If
I=i+2
Else
Newstr=newstr & Char_c
End If
Next
Urldecode=newstr
End Function