web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Automate
Answered

URL Encoding

(0) ShareShare
ReportReport
Posted on by 431
I tried this VB script but got error: VBScript runtime error: Sub or Function not defined.
Function EncodeURL(ByVal str)
    encodedStr = ""
    For i = 1 To Len(str)
        c = Mid(str, i, 1)
        If c Like "[A-Za-z0-9-_.~]" Then
            encodedStr = encodedStr & c
        Else
            encodedStr = encodedStr & "%%" & Hex(AscB(c))
        End If
    Next
    EncodeURL = encodedStr
End Function

inputString = "abd def"
encodedString = EncodeURL(inputString)
WScript.Echo  encodedString
 
I have the same question (0)
  • Verified answer
    eetuRobo Profile Picture
    4,204 Super User 2025 Season 2 on at
    I think VBScript doesn't have Like operator. You need to use InStr instead.

    Try something like this:
    Function EncodeURL(ByVal str)
        Dim encodedStr, i, c
        encodedStr = ""
        allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"
    
        For i = 1 To Len(str)
            c = Mid(str, i, 1)
            If InStr(allowedChars, c) > 0 Then
                encodedStr = encodedStr & c
            Else
                encodedStr = encodedStr & "%%" & Hex(Asc(c)) ' Keep PAD's double %%
            End If
        Next
    
        EncodeURL = encodedStr
    End Function
    
    inputString = "abd def"
    encodedString = EncodeURL(inputString)
    WScript.Echo encodedString
    
     
    Or you can try with JavaScript which should be more simple: https://www.samurai-emblem.com/2023/08/11/power-automate-desktop-url-encode-decode/

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard