We help IT Professionals succeed at work.

HTML Decode URL

webdork
webdork asked
on
1,006 Views
Last Modified: 2012-02-15
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
Comment
Watch Question

Scott FellDeveloper
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013

Commented:
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

Author

Commented:
I see... I think.

How call function?
Developer
CERTIFIED EXPERT
Fellow
Most Valuable Expert 2013
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
thanks, works great.
Top Expert 2011

Commented:
@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.)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.