VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



URLDecode Function

by Markus Diersbock (2 Submissions)
Category: VB function enhancement
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

Decodes a URLEncoded string

Inputs
sEncodedURL - Encoded String to Decode
Code Returns
Decoded String

Rate URLDecode Function

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

Download this snippet    Add to My Saved Code

URLDecode Function Comments

No comments have been posted about URLDecode Function. Why not be the first to post a comment about URLDecode Function.

Post your comment

Subject:
Message:
0/1000 characters