Community
    • Login

    How do I sort strings separated by commas?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 115 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C BaccaC
      C Bacca
      last edited by C Bacca

      How do I sort these comma-delimited strings in Notepad++ v8.1.5 from 2021? Sorry Notepad++ cannot be updated right now I’m in the middle of a rush project.

      zk1, abc, 11a, bba1, lakw, lw1, ffs, lla, lla1, zxk2

      If I use Python REPL the strings have to be quoted and I have many more strings than in the example above.

      print(sorted('zk1', 'abc', '11a'))

      This is a common task that I have. Whether I’m sorting variable names on the same line, or items in a comma-separated list. Sometimes the items are separated by a semi-colon “;”.

      Thank you.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @C Bacca
        last edited by

        @C-Bacca:

        Step 1: Select the strings (on a single line, do not include the line ending)
        Step 2: Ctrl+h replace , with \r\n taking care to checkmark Regular expression and In selection
        Step 3: Run your desired sort (down in the Line operations submenu on the Edit menu)
        Step 4: Ctrl+h replace \r\n with , taking care to checkmark Regular expression and In selection

        dr ramaanandD C BaccaC 2 Replies Last reply Reply Quote 5
        • dr ramaanandD
          dr ramaanand @Alan Kilborn
          last edited by dr ramaanand

          @C-Bacca if the solution/answer provided by @Alan-Kilborn is not what you are looking for, please let us know what you mean by “sort out”. If you want to replace the strings just before each , (comma) you can hit ctrl+h and in the pop-up, select the regular expression mode, put (^|, )(.*?)(?=,) in the Find field, $1uniquestring in the Replace field and hit Replace/Replace All which will replace all your strings with the term, “uniquestring” - remember that if you hit only Replace, you have to replace each string, one at a time

          1 Reply Last reply Reply Quote 0
          • C BaccaC
            C Bacca @Alan Kilborn
            last edited by

            @Alan-Kilborn This is what I want. But is there a way to make this a series of steps, like a macro, and link the macro to a single key press?

            I’m trying to minimize key presses here. I can get super busy at times.

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @C Bacca
              last edited by

              @C-Bacca said in How do I sort strings separated by commas?:

              is there a way to make this a series of steps, like a macro,

              Yes, you should be able to record it and save it as a macro.
              Note that Step 1 would not be part of the macro, but would be something that you have to do before running the macro.
              For more on macros see HERE.

              1 Reply Last reply Reply Quote 4
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors