Skip to content

Instantly share code, notes, and snippets.

@nordinrahman
Created February 24, 2014 06:46
Show Gist options
  • Save nordinrahman/9183032 to your computer and use it in GitHub Desktop.
Save nordinrahman/9183032 to your computer and use it in GitHub Desktop.
ASP code to URL-decode a query string
' -----------------------------------------
' 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment