Right now:
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 in 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:
The code copy is as follows:
functionurldecode(encodestr)
newsstr=""
havechar=false
lastchar=""
fori=1tolen(encodestr)
char_c=mid(encodestr,i,1)
ifchar_c="+"then
newsstr=newstr&""
elseifchar_c="%"then
next_1_c=mid(encodestr,i+1,2)
next_1_num=cint("&H"&next_1_c)
ifhavecharthen
havechar=false
newsstr=newstr&chr(cint("&H"&lastchar&next_1_c))
else
ifabs(next_1_num)<=127then
newsstr=newstr&chr(next_1_num)
else
havechar=true
lastchar=next_1_c
endif
endif
i=i+2
else
newsstr=newstr&char_c
endif
next
urldecode=newstr
endfunction
Here is a more mature function for you:
The code copy is as follows:
'==================================================================
'Function name: URLDecode
'Function: URL decoding
'==================================================================
Function URLDecode(ByVal urlcode)
Dim start, final, length, char,i,butf8,pass
Dim leftstr,rightstr,finalstr
Dim b0,b1,bx,blength,position,u,utf8
On Error Resume Next
b0 = Array(192,224,240,248,252,254)
urlcode = Replace(urlcode,"+"," ")
pass = 0
utf8 = -1
length = Len(urlcode) : start = InStr(urlcode,"%") : final = InStrRev(urlcode,"%")
If start = 0 Or length < 3 Then URLDecode = urlcode : Exit Function
leftstr = Left(urlcode,start - 1) : rightstr = Right(urlcode,length - 2 - final)
For i = start To final
char = Mid(urlcode,i,1)
If char = "%" Then
bx = URLDecode_Hex(Mid(urlcode,i + 1,2))
If bx > 31 And bx < 128 Then
i = i + 2
finalstr = finalstr & ChrW(bx)
ElseIf bx > 127 Then
i = i + 2
If utf8 < 0 Then
butf8 = 1 : blength = -1 : b1 = bx
For position = 4 To 0 Step -1
If b1 >= b0(position) And b1 < b0(position + 1) Then
blength = position
Exit For
End If
Next
If blength > -1 Then
For position = 0 To blength
b1 = URLDecode_Hex(Mid(urlcode,i + position * 3 + 2,2))
If b1 < 128 Or b1 > 191 Then butf8 = 0 : Exit For
Next
Else
butf8 = 0
End If
If butf8 = 1 And blength = 0 Then butf8 = -2
If butf8 > -1 And utf8 = -2 Then i = start - 1 : finalstr = "" : pass = 1