Sign in to follow this  
Followers 0
Andrew Sparkes

A function to escape/encode a URL string ?

2 posts in this topic

I hunted through the beta's helpfile and did a number of searches here, but have found nothing... What I need is a function to escape a string (using % as escape char) so it can pass nicely into a GET request. It has the same function as escape() in Javascript, but I need it in autoit. I can do it myself, but I was wondering if someone had already done it. If no one has done it, I'll use www.w3schools.com's reference and put the final function in scripts and scraps...

i.e. turning

'email=myname@mydomain.com&password=mypass'

into

'email=myname%40mydomain.com&password=mypass'

Thanks,

Sparkes.


---Sparkes.

Share this post


Link to post
Share on other sites



I thought it was too easy of a problem to wait for it, so I wrote my own:

Tell me if there are any problems, it should work right... it escapes all characters that aren't alphanumeric or a period.

Func URLEscape($text)
    $newtext=''
    For $x=1 To StringLen($text)
        $char=StringMid($text,$x,1)
        If StringRegExp($char,'\A|\.',0) Then
            $newchar=$char
        Else
            $newchar="%"&Hex(Asc($char),2)
        EndIf
        $newtext=$newtext&$newchar
    Next
    Return $newtext
EndFunc

---Sparkes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0