URL encoding/decoding macros?

URL encoding/decoding macros?

20
Basic UserBasic User
20

    Oct 25, 2007#1

    :?:

    For URL encoding, is there an easy way to do this? Maybe a macro someones already made and can share? Or, do I at least have the right idea on how to make it?

    I want to take a link like this.

    Code: Select all

    http://search.ebay.com/search/search.dll?sofocus=bs&sbrftog=1&from=R10&satitle=G4+apple+software&sacat=-1%26catref%3DC6&sargn=-1%26saslc%3D2&sadis=200&fpos=44870&sabfmts=1&ftrt=1&ftrv=1&saprclo=&saprchi=&fsop=1%26fsoo%3D1&coaction=compare&copagenum=1&coentrypage=search&fgtp=
    and end up with something like this... (and another macro to do vice versa)

    Code: Select all

    http%3A%2F%2Fsearch.ebay.com%2Fsearch%2Fsearch.dll%3Fsofocus%3Dbs%26sbrftog%3D1%26from%3DR10%26satitle%3DG4%2Bapple%2Bsoftware%26sacat%3D-1%2526catref%253DC6%26sargn%3D-1%2526saslc%253D2%26sadis%3D200%26fpos%3D44870%26sabfmts%3D1%26ftrt%3D1%26ftrv%3D1%26saprclo%3D%26saprchi%3D%26fsop%3D1%2526fsoo%253D1%26coaction%3Dcompare%26copagenum%3D1%26coentrypage%3Dsearch%26fgtp%3D
    Maybe by replacing the symbols like (replace : by %3A, replace / by %2F, etc.)

    It would probably take me a long time to make a macro and I'm not sure it could even be done so I appreciate any advice. Do I have the right idea to make it?

    More on URL encoding: http://www.blooberry.com/indexdot/html/ ... coding.htm

    262
    MasterMaster
    262

      Re: URL encoding/decoding Macros?

      Oct 25, 2007#2

      You don't write which version of UE you use, but if you use version 13 and above the most easy solution is a script using the javascript encodeURIComponent function:

      Example: Select the URL (the link) in your editor and run the script:

      Code: Select all

      /* get selected text in the active file */
      var line = UltraEdit.activeDocument.selection;
      
      /* URI encode string */
      line = encodeURIComponent(line);
      
      /* write line back on top of selection */
      UltraEdit.activeDocument.write(line);

      6,675585
      Grand MasterGrand Master
      6,675585

        Re: URL encoding/decoding Macros?

        Oct 25, 2007#3

        In the Advanced toolbar profile there is the HTML toolbar which contains the function HTML Encode/Decode. This can be also used. But note: It encodes the selection completely including the letters and numbers and not only all other characters.
        Best regards from an UC/UE/UES for Windows user from Austria

        20
        Basic UserBasic User
        20

          Re: URL encoding/decoding Macros?

          Oct 25, 2007#4

          Thank you jorrasdk but I should have told you I am using v 12 of UE. I should probably upgrade.

          Mofi, That's great and I didnt know about it but I just wish it had another option to just encode/decode special characters.
          UE is the greatest along with the forum members.

          Thanks guys so much.

          262
          MasterMaster
          262

            Re: URL encoding/decoding Macros?

            Oct 25, 2007#5

            Ok with a macro you will have a number of search/replaces - this takes care of the most frequent characters that needs to be encoded. It selects from the cursor position to the end of the line:

            Code: Select all

            InsertMode
            ColumnModeOff
            HexOff
            UnixReOff
            StartSelect
            Key END
            Find "%"
            Replace All SelectText "%25"
            Find "@"
            Replace All SelectText "%40"
            Find ";"
            Replace All SelectText "%3B"
            Find "?"
            Replace All SelectText "%3F"
            Find "/"
            Replace All SelectText "%2F"
            Find ":"
            Replace All SelectText "%3A"
            Find "#"
            Replace All SelectText "%23"
            Find "&"
            Replace All SelectText "%24"
            Find "="
            Replace All SelectText "%3D"
            Find "+"
            Replace All SelectText "%2B"
            Find "$"
            Replace All SelectText "%26"
            Find ","
            Replace All SelectText "%2C"
            Find " "
            Replace All SelectText "%20"
            Find "<"
            Replace All SelectText "%3C"
            Find ">"
            Replace All SelectText "%3E"
            Find "~"
            Replace All SelectText "%7E"

            20
            Basic UserBasic User
            20

              Re: URL encoding/decoding Macros?

              Oct 25, 2007#6

              Thank you very much for taking the time to make this Jorrasdk.
              It works perfectly! You guys are the best!

                Re: URL encoding/decoding Macros?

                Dec 27, 2007#7

                Is there anyone who can tell me the simplest way to use this macro to encode only the urls in a file and not mess with any of the other coding?

                I have this huge file with thousands of urls and lots of coding in it.
                All the urls are totally different but they all have one thing in common.

                They all begin with (' and end with ')

                example: ('http://www.google.com/search?q=ultraedit')

                So would I be able to have it only change whats between the (' and the ') or some way to do it by editing the macro and using something like ('^(*^)') but I have no idea how?

                Im still on UE version 12. Any ideas?

                262
                MasterMaster
                262

                  Re: URL encoding/decoding Macros?

                  Dec 27, 2007#8

                  Ok, let's assume you have named the macro above encode. Next create the macro in the following and name it findurls:

                  InsertMode
                  ColumnModeOff
                  HexOff
                  Top
                  Loop
                  PerlReOn
                  Find RegExp "
                  \('(?:https|http|ftp)[^']+'\)"
                  IfFound
                  PlayMacro 1 "encode"
                  Else
                  ExitLoop
                  EndIf
                  EndLoop
                  Top


                  The red part is a Perl regular expression *) that selects an embedded URL with the pattern you described. To be sure it only finds URLs the regular expression only selects what seems to be URLs starting with https,http or ftp. Add more of these if you use other protocols for URLs (or rather URI's).

                  *) UE version always matters, so since you wrote you use version 12, I was able to use a Perl regular expression which is more powerful than UE or Unix style regular expressions.

                  20
                  Basic UserBasic User
                  20

                    Re: URL encoding/decoding Macros?

                    Dec 27, 2007#9

                    Thanks so much Jorrasdk, I use that original macro you created a lot!!
                    I'm not sure what I am doing wrong with this one, unfortunately it's not working for me. I renamed the original to encode and the new one to findurls, then loaded them both and ran findurls. I tried many times but the page seems to jump like it trys to do something but Nothing happened.

                    Another thing I wanted to add, if it matters, is that there are lots of ( ) and lots of ' ' in this file but the only (' ') are the ones before and after the URLs
                    so I'm not sure if searching for https|http|ftp is needed. Isn't there a way to just search for everything between (' ') ?

                    I hope that I made sense there.

                    I did spend a long time searching the forum for an answer before I bumped this thread by asking so I hope you don't think I only come for an easy answer. I realy appreciate the help you guys give. Thanks again!

                    262
                    MasterMaster
                    262

                      Re: URL encoding/decoding Macros?

                      Dec 27, 2007#10

                      Ok, then we need to see an example of your actual data - please supply information as described in section 4 and 5 of the thread Help for new forum members - read this before post anywhere!

                      it could be the data, or that my macro tested on 13.20a doesn't work on your version 12.??? something because of not supported commands or bugs fixed in later UE versions. But I would like to try the macros on your actual data.

                      20
                      Basic UserBasic User
                      20

                        Re: URL encoding/decoding Macros?

                        Dec 27, 2007#11

                        Thank you!

                        Yeah, it's probably time for me to upgrade. I will definatley have to look into it.

                        This is just two lines from my file(not working links), times it by almost 4000 and thats what it looks like. 8O

                        Code: Select all

                        <menuit id="77688" label="PC & V" oncommand="srchau881281();"/>
                        <menuit id="50201" label="Deskt" oncommand="LoadPage('http://google.com//11006159695/1108274&2264263&QQlogZ0QQsacatZ3736QQsrgnZsaliQQsocmdZ');"/>
                        <menuit id="50202" label="Input Peripherals'" oncommand="LoadPage('http://google.com/1/71006159695/1?=226463&atZ3676QsargnZsalicQQsocmdZ');"/>

                        262
                        MasterMaster
                        262

                          Re: URL encoding/decoding Macros?

                          Dec 27, 2007#12

                          Ok, I tested my macro on too simple test data. With your proper example I found some problems:

                          Alter encode to

                          Code: Select all

                          ColumnModeOff
                          HexOff
                          Find "%"
                          Replace All SelectText "%25"
                          Find "@"
                          Replace All SelectText "%40"
                          Find ";"
                          Replace All SelectText "%3B"
                          Find "?"
                          Replace All SelectText "%3F"
                          Find "/"
                          Replace All SelectText "%2F"
                          Find ":"
                          Replace All SelectText "%3A"
                          Find "#"
                          Replace All SelectText "%23"
                          Find "&"
                          Replace All SelectText "%24"
                          Find "="
                          Replace All SelectText "%3D"
                          Find "+"
                          Replace All SelectText "%2B"
                          Find "$"
                          Replace All SelectText "%26"
                          Find ","
                          Replace All SelectText "%2C"
                          Find " "
                          Replace All SelectText "%20"
                          Find "<"
                          Replace All SelectText "%3C"
                          Find ">"
                          Replace All SelectText "%3E"
                          Find "~"
                          Replace All SelectText "%7E"
                          and alter findurls to

                          Code: Select all

                          InsertMode
                          ColumnModeOff
                          HexOff
                          UnixReOff
                          Top
                          Loop 
                          Find RegExp "('*')"
                          IfFound
                          PlayMacro 1 "encode"
                          Else
                          ExitLoop
                          EndIf
                          EndLoop
                          Top
                          I have taken Perl RegExp out of the equation and now use a very simple UE style RegExp: ('*')

                          20
                          Basic UserBasic User
                          20

                            Re: URL encoding/decoding Macros?

                            Dec 28, 2007#13

                            It's perfect! Thank you so much jorrasdk! I wish you the best and Happiest New Year!!

                            :lol: :wink: :D


                            PS. My New Year resolution is to Update UE and learn more!