How to have each text-line of each list in its own line, instead of having all of them together in the same single line. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rx65m
Posts: 19
Joined: 16 Mar 2018, 17:29

How to have each text-line of each list in its own line, instead of having all of them together in the same single line.

Post by rx65m » 23 Dec 2022, 02:13

I have this code to randomly choose one line of text from each of the three lists of text-lines within the same file, and copy them together to the clipboard.
It works perfectly fine, but it is not practical to add new lines of long text to the code.
So I wonder if it is possible editing it to have each text-line in its own separated line in the code, instead of having all text-lines of each list in one single line, as it is right now.

For instance instead of having each list like this:
list = 1st text-line,2nd text-line,3rd text-line,4th text-line
better have them similar to something like this:
list =
1st text-line,
2nd text-line,
3rd text-line,
4th text-line
I've tried several options I know, but all I get are blank lines.

This is my current code:

Code: Select all

Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4

; Definining 3 lists of text lines:
list1 = 1st text-line,2nd text-line,3rd text-line,4th text-line
list2 = 5th text-line,6th text-line,7th text-line,8th text-line
list3 = 9th text-line,10th text-line,11th text-line,12th text-line

; Selecting randomly one text-line from each list:
selectedLine1 := strsplit(list1,",")[rand1]
selectedLine2 := strsplit(list2,",")[rand2]
selectedLine3 := strsplit(list3,",")[rand3]

; Concatenating the 3 selected text-lines and copy them to the clipboard:
clipboard = %selectedLine1%`n%selectedLine2%`n%selectedLine3%

; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%
My AutoHotkey is version 1.1.36.02 . Thanks in advance for your help.

User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: How to have each text-line of each list in its own line, instead of having all of them together in the same single l  Topic is solved

Post by flyingDman » 23 Dec 2022, 02:27

Code: Select all

Random, rand1, 1, 4
Random, rand2, 1, 4
Random, rand3, 1, 4

; Definining 3 lists of text lines:
list1 =
(
1st text-line
2nd text-line
3rd text-line
4th text-line
)
list2 =
(
5th text-line
6th text-line
7th text-line
8th text-line
)
list3 =
(
9th text-line
10th text-line
11th text-line
12th text-line
)

; Selecting randomly one text-line from each list:
selectedLine1 := strsplit(list1,"`n")[rand1]
selectedLine2 := strsplit(list2,"`n")[rand2]
selectedLine3 := strsplit(list3,"`n")[rand3]

; Concatenating the 3 selected text-lines and copy them to the clipboard:
clipboard = %selectedLine1%`n%selectedLine2%`n%selectedLine3%

; Seeing the result on a message box:
msgbox, Randoms: %rand1%, %rand2%, %rand3%`nSelected lines:`n%selectedLine1%`n%selectedLine2%`n%selectedLine3%
14.3 & 1.3.7

rx65m
Posts: 19
Joined: 16 Mar 2018, 17:29

Re: How to have each text-line of each list in its own line, instead of having all of them together in the same single l

Post by rx65m » 23 Dec 2022, 02:34

Thanks a lot flyingDman
Once again, it works fantastic!

Post Reply

Return to “Ask for Help (v1)”