Community
    • Login

    How do I sort strings separated by commas?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 1.2k Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Offline
            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 Offline
              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

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors