Private Sub Form_Load()
x = "%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3"
MsgBox decode(x)
End Sub
Function decode(ByVal x As String) As String
'x = "%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3"
Dim temp
Dim i As Long
temp = Split(x, "%")
For i = 1 To UBound(temp) Step 2
decode = decode & Chr("&H" & temp(i) & temp(i + 1))
Next
Public Function UrlDecode(ByVal sEncoded As String) As String
'========================================================
' Accept url-encoded string
' Return decoded string
'========================================================
Dim pos As Long ' position of InStr target
Dim i As Integer, lastpos As Integer, flag As Boolean
Dim temp As String, outstr As String
If sEncoded = "" Then Exit Function
' convert "+" to space
pos = 0
Do
pos = InStr(pos + 1, sEncoded, "+")
If pos = 0 Then Exit Do
Mid$(sEncoded, pos, 1) = " "
Loop
' convert "%xx%xx" to chinese character
pos = 0
On Error Resume Next
i = 0
Do
pos = InStr(pos + 1, sEncoded, "%")
If pos = 0 Then
If lastpos <> 0 Then
outstr = outstr & Mid(sEncoded, lastpos + 3)
End If
Exit Do
End If
lastpos = pos
If flag = False Then
outstr = Left$(sEncoded, pos - 1)
flag = True
End If
temp = temp & Mid$(sEncoded, pos + 1, 2)
i = i + 1
If i Mod 2 = 0 Then
outstr = outstr & Chr$("&H" & temp)
temp = ""
End If
Loop
On Error GoTo 0 'reset error handling
If flag = True Then
UrlDecode = outstr
Else
UrlDecode = sEncoded
End If
End Function
Private Sub Command1_Click()
Dim s As String
s = "%B2%BB%B4%ED%A3%AC%D6%A7%B3%D6%A1%A3"
s = UrlDecode(s)
Debug.Print s