Please help me to sort unordered comma separated words Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aya141
Posts: 2
Joined: 31 Oct 2019, 06:28

Please help me to sort unordered comma separated words

31 Oct 2019, 08:55

I work as part time data entry. My manager asks me to tag documents with different keywords.

For example:

I have to write at the end of documents -
unconnected, 0item, *important, support, check, _j.smith, product
But, he wants me to write those keywords in alphabetical order below.
*important, 0item, _j.smith, check, product, support, unconnected
Is it possible to sort unordered comma separated words in alphabetical order using AutoHotKey?

Thank you so much!
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Please help me to sort unordered comma separated words

31 Oct 2019, 09:31

Example

Code: Select all

tmp := "unconnected, 0item, *important, support, check, _j.smith, product"
Sort, tmp, D,
MsgBox % tmp
This is using the Sort method found here https://www.autohotkey.com/docs/commands/Sort.htm
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Please help me to sort unordered comma separated words  Topic is solved

31 Oct 2019, 10:06

Some ideas. Note: if you sort by commas, you have to be careful handling spaces.

Code: Select all

q:: ;sort comma/space-separated list - first attempt (don't use this)
vText := "qwe, rty, uio, pas"
Sort, vText, D,
Clipboard := vText
MsgBox, % "[" vText "]" ;[ pas, rty, uio,qwe]
return
;note: leading space
;note: no space before 'qwe'

w:: ;sort comma/space-separated list - improved attempt 1
vText := "qwe, rty, uio, pas"
vText := " " Trim(vText)
Sort, vText, D,
vText := Trim(vText)
Clipboard := vText
MsgBox, % "[" vText "]" ;[pas, qwe, rty, uio]
return

e:: ;sort comma/space-separated list - improved attempt 2
vText := "qwe, rty, uio, pas"
vText := StrReplace(vText, ", ", Chr(1))
Sort, vText, % "D" Chr(1)
vText := StrReplace(vText, Chr(1), ", ")
Clipboard := vText
MsgBox, % "[" vText "]" ;[pas, qwe, rty, uio]
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
aya141
Posts: 2
Joined: 31 Oct 2019, 06:28

Re: Please help me to sort unordered comma separated words

31 Oct 2019, 10:53

Hi... @jeeswg

Thank you so much for snippet! It really WORKS!!!

That will surely boost my productivity at work.

:superhappy: :rainbow: :superhappy:

Code: Select all

e:: ;sort comma/space-separated list - improved attempt 2
vText := "qwe, rty, uio, pas"
vText := StrReplace(vText, ", ", Chr(1))
Sort, vText, % "D" Chr(1)
vText := StrReplace(vText, Chr(1), ", ")
Clipboard := vText
MsgBox, % "[" vText "]" ;[pas, qwe, rty, uio]
return
Millions of THANKS!!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot], macromint, peter_ahk and 333 guests