• Login
Community
  • Login

How do I sort strings separated by commas?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 121 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
    C Bacca
    last edited by C Bacca May 1, 2025, 9:23 AM May 1, 2025, 9:21 AM

    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.

    A 1 Reply Last reply May 1, 2025, 10:04 AM Reply Quote 0
    • A
      Alan Kilborn @C Bacca
      last edited by May 1, 2025, 10:04 AM

      @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

      D C 2 Replies Last reply May 1, 2025, 10:18 AM Reply Quote 5
      • D
        dr ramaanand @Alan Kilborn
        last edited by dr ramaanand May 1, 2025, 10:42 AM May 1, 2025, 10:18 AM

        @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
          C Bacca @Alan Kilborn
          last edited by May 1, 2025, 11:27 AM

          @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.

          A 1 Reply Last reply May 1, 2025, 11:32 AM Reply Quote 0
          • A
            Alan Kilborn @C Bacca
            last edited by May 1, 2025, 11:32 AM

            @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
            1 out of 5
            • First post
              1/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors