Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does VBA have any built in URL decoding?

Tags:

url

vba

urldecode

I just need to decode a URL, for example, replace %2E with . I can hack out a method if one isn't build in, but my assumption is that there must be a URL decoding tool already existing.

like image 708
Russell Steen Avatar asked Feb 14 '11 23:02

Russell Steen


People also ask

Does browser automatically decode URL?

It is a usual task in web development, and this is generally done while making a GET request to the API with the query params. The query params must also be encoded in the URL string, where the server will decode this. Many browsers automatically encode and decode the URL and the response string.

How do I decode a URL in PowerShell?

PowerShell Code to handle the URL encoding and decoding:HttpUtility]::UrlEncode($urlToEncode) Write-Host "The encoded url is: " $encodedURL -ForegroundColor Green #Encode URL code ends here #The below code is used to decode the URL. $urlTodDecode = $encodedURL $decodedURL = [System. Web.

What does URL decode do?

URL encoding converts characters that are not allowed in a URL into character-entity equivalents; URL decoding reverses the encoding. For example, when embedded in a block of text to be transmitted in a URL the characters < and > are encoded as %3c and %3e.


1 Answers

Here's a snippet I wrote years ago

-markus

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
    URLDecode = sRtn
End If

Finally:
    Exit Function
Catch:
    URLDecode = ""
    Resume Finally
End Function
like image 57
markus diersbock Avatar answered Sep 21 '22 21:09

markus diersbock