How do I sort strings separated by commas?
-
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.
-
Step 1: Select the strings (on a single line, do not include the line ending)
Step 2: Ctrl+h replace,with\r\ntaking 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\nwith,taking care to checkmark Regular expression and In selection -
@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 theFindfield,$1uniquestringin theReplacefield 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 -
@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.
-
@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.
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