Link to home
Start Free TrialLog in
Avatar of webdork
webdork

asked on

HTML Decode URL

I need to decode a string return. I can do the encode, not sure of the decode.

Like this, TOKEN value needs to be decode.

TOKEN=EC%2d388178183U924443N
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

There is no real "urldecode"   Here is a function I use but basically you are just using the replace function to search for the % and convert it.   So %20 turns to a space etc.


' -----------------------------------------
' URL decode to retrieve the original value

Function URLDecode(sConvert)
    Dim aSplit
    Dim sOutput
    Dim I
    If IsNull(sConvert) Then
       URLDecode = ""
       Exit Function
    End If

    ' convert all pluses to spaces
    sOutput = REPLACE(sConvert, "+", " ")

    ' next convert %hexdigits to the character
    aSplit = Split(sOutput, "%")

    If IsArray(aSplit) Then
      sOutput = aSplit(0)
      For I = 0 to UBound(aSplit) - 1
        sOutput = sOutput & _
          Chr("&H" & Left(aSplit(i + 1), 2)) &_
          Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
      Next
    End If

    URLDecode = sOutput
End Function
Avatar of webdork
webdork

ASKER

I see... I think.

How call function?
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of webdork

ASKER

thanks, works great.
@WebDork - just saw your link to this question from your other question.
Padas already provided the exact same function I was going to post.

Funny that I happened to be working on a page earlier this morning that is nearly identical to your quest.  (Taking a URLEncoded value (a URL), decoding it and spitting it into the different parameters by splitting it on the "&" and then the "=" to get specific param values I am looking for.)