VB icon

URLDecode Function

Submitted on: 1/31/2015 7:25:00 PM
By: Markus Diersbock (from psc cd)  
Level: Intermediate
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0, ASP (Active Server Pages)
Views: 4002
     Decodes a URLEncoded string
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
' Name: URLDecode Function
' Description:Decodes a URLEncoded string
' By: Markus Diersbock (from psc cd)
' Inputs:sEncodedURL - Encoded String to Decode
' Returns:Decoded String

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
 Exit Function
 URLDecode = ""
 Resume Finally
End Function

Other 1 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.