URL encoding is an encoding method that must be replaced with characters of special meaning in order to pass information through URLs. In ASP, we all know a function of the server. The following is the editor of the new technology channel of the Error Technology Channel to introduce you to how to implement URL encoding in ASP. Let’s take a look!
If there are spaces, use %20 instead, if there are other characters, use %ASCII instead. If there are four byte characters such as Chinese characters, use two %ASCII instead. However, sometimes we also need to decode the strings encoded in this way, but asp does not provide relevant functions, which brings some trouble to us when dealing with 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:
Copy the code as follows: function urldecode(encodestr)newsstr=""
havechar=false
lastchar=""
for i=1 to len(encodestr)
char_c=mid(encodestr,i,1)
if char_c="+" then
newsstr=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
newsstr=newstr & chr(cint("&H" & lastchar & next_1_c))
else
if abs(next_1_num)<=127 then
newsstr=newstr & chr(next_1_num)
else
havechar=true
lastchar=next_1_c
end if
end if
i=i+2
else
newsstr=newstr & char_c
end if
next
urldecode=newstr
end function
Through the introduction of the editor of the Error New Technology Channel, everyone has learned the knowledge in ASP. We must consolidate the functions we do not use frequently during our work, so we will not be helpless when we need to use them.