Jump to content

A function to escape/encode a URL string ?


Recommended Posts

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.

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...