README.md

December 4, 2022 ยท View on GitHub

URLDecode Function

Description

Decodes a URLEncoded string

More Info

sEncodedURL - Encoded String to Decode

Decoded String

Submitted On
ByMarkus Diersbock
LevelIntermediate
User Rating4.5 (27 globes from 6 users)
CompatibilityVB 5.0, VB 6.0, ASP (Active Server Pages)
CategoryVB function enhancement
WorldVisual Basic
Archive File

Source Code

Public Function URLDecode(sEncodedURL As String) As String
 On Error GoTo Catch
 Dim iLoop As Integer
 Dim sRtn As String
 Dim sTmp As String
 If Len(sEncodedURL) > 0 Then
 ' Loop through each char
 For iLoop = 1 To Len(sEncodedURL)
 sTmp = Mid(sEncodedURL, iLoop, 1)
 sTmp = Replace(sTmp, "+", " ")
 ' If char is % then get next two chars
 ' and convert from HEX to decimal
 If sTmp = "%" and LEN(sEncodedURL) + 1 > iLoop + 2 Then
 sTmp = Mid(sEncodedURL, iLoop + 1, 2)
 sTmp = Chr(CDec("&H" & sTmp))
 ' Increment loop by 2
 iLoop = iLoop + 2
 End If
 sRtn = sRtn & sTmp
 Next iLoop
 URLDecode = sRtn
 End If
Finally:
 Exit Function
Catch:
 URLDecode = ""
 Resume Finally
End Function