This task   (the reverse of   URL encoding   and distinct from   URL parser)   is to provide a function
or mechanism to convert an URL-encoded string into its original unencoded form.



Test cases

   The encoded string   "http%3A%2F%2Ffoo%20bar%2F"   should be reverted to the unencoded form   "http://foo bar/".
   The encoded string   "google.com/search?q=%60Abdu%27l-Bah%C3%A1"   should revert to the unencoded form   "google.com/search?q=`Abdu'l-Bahá".


 
Const alphanum = "0123456789abcdefghijklmnopqrstuvwxyz"
 
Function ToDecimal (cadena As String, base_ As Uinteger) As Uinteger 
    Dim As Uinteger i, n, result = 0
    Dim As Uinteger inlength = Len(cadena)
 
    For i = 1 To inlength
        n = Instr(alphanum, Mid(Lcase(cadena),i,1)) - 1
        n *= (base_^(inlength-i))
        result += n
    Next 
    Return result
End Function
 
Function url2string(cadena As String) As String
    Dim As String c, nc, res
 
    For j As Integer = 1 To Len(cadena)
        c = Mid(cadena, j, 1)
        If c = "%" Then
            nc = Chr(ToDecimal((Mid(cadena, j+1, 2)), 16))
            res &= nc
            j += 2
        Else
            res &= c
        End If
    Next j
    Return res
End Function
 
Dim As String URL = "http%3A%2F%2Ffoo%20bar%2F"
 
Print "Supplied URL '"; URL; "'"
Print "URL decoding '"; url2string(URL); "'"
 
URL = "google.com/search?q=%60Abdu%27l-Bah%C3%A1"
Print !"\nSupplied URL '"; URL; "'"
Print "URL decoding '"; url2string(URL); "'"
Sleep
 