Split text block into random amount of words Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chango
Posts: 30
Joined: 27 May 2017, 12:10

Split text block into random amount of words

06 Feb 2020, 11:16

I have some large text blocks and I want to split then into lines with a set or random amount of words

SO my sudo is

Open textX file
Loop until words remaining is less than 15 (length of string)
Count 15 - 20 spaces (in between word space) String = Words(count)
Add full stop
Carriage return
Loop
Save FileX

Any help would be much appreciated :)
Albireo
Posts: 1778
Joined: 16 Oct 2013, 13:53

Re: Split text block into random amount of words

07 Feb 2020, 10:07

Have you started with any solution?
Where did you get stuck?
(Open file? count spaces / new lines or...)
chango
Posts: 30
Joined: 27 May 2017, 12:10

Re: Split text block into random amount of words

07 Feb 2020, 12:23

Opening files and reading into a array I can do i thought there might be a simple regex formula for counting spaces and then stopping, I might try a .slpit function and pass it back to the txt file. I'll post what i have when I've got my head around regex.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Split text block into random amount of words  Topic is solved

07 Feb 2020, 12:51

Some like this ?

Code: Select all

word_per_row := 5
list=
(
 Fusce nisi dolor, venenatis sed nunc sed, aliquam condimentum libero. Fusce dictum mauris sit amet fermentum interdum. Donec ullamcorper aliquet odio, et pulvinar mi auctor ut. Duis ut eleifend ligula. Phasellus tincidunt, enim sed euismod faucibus, ipsum sem
 ultrices nunc, vel eleifend velit nunc ac neque. Duis feugiat diam et semper gravida. Fusce ac lectus id mi cursus auctor. Maecenas lobortis velit ac lorem convallis, at tristique urna mattis. Aliquam eu feugiat odio. Quisque porta nunc a nisi pharetra cursus. Proin eleifend
 tincidunt neque ut tincidunt. Praesent nunc elit, lacinia quis condimentum vitae, sagittis et lectus. Suspendisse at interdum lorem, non cursus nulla. Maecenas suscipit ac lacus eget pellentesque.
Donec ut turpis quam. Vivamus placerat sollicitudin nunc eget laoreet. Maecenas vitae velit elit. Phasellus ac finibus odio. Aliquam erat volutpat. Praesent nunc lorem, convallis a pharetra sed, luctus ac quam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur semper imperdiet semper. Donec eget tempor libero. Morbi eleifend dolor eu mi fermentum, nec hendrerit elit accumsan. Aliquam id tellus pellentesque, dignissim nisi eu, porta dui. Nullam suscipit dolor in ipsum iaculis tempor. Nulla semper et metus sit amet venenatis. Vivamus ut tincidunt velit. 
)
;------------------------------------------------------------------------------------------------***
; I use a list but if you want to read from a file uncomment the line below
; FileRead, List, your_input_file.txt
;------------------------------------------------------------------------------------------------***

for k, v in StrSplit(RegExReplace(list,"\s+"," ")," ") {
   if (Mod(k,word_per_row)) = 0
      str .= v "`n" 
   else str .= v " " 
}
FileDelete, outFile.txt
FileAppend, %str%, outFile.txt
run, outFile.txt
ExitApp
Last edited by Odlanir on 08 Feb 2020, 04:15, edited 1 time in total.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
chango
Posts: 30
Joined: 27 May 2017, 12:10

Re: Split text block into random amount of words

07 Feb 2020, 16:11

Thanks Odlanir ! I'll give that a try when I get home and let you know how it goes.. again many thanks for the help :)
chango
Posts: 30
Joined: 27 May 2017, 12:10

Re: Split text block into random amount of words

08 Feb 2020, 08:44

@Odlanir

That is insane lol So simple and yet so perfect for the task I need it for .. many many thanks mate :)
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Split text block into random amount of words

08 Feb 2020, 10:10

Glad if worked OK for your needs !
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
Chunjee
Posts: 1501
Joined: 18 Apr 2014, 19:05
Contact:

Re: Split text block into random amount of words

18 Feb 2020, 07:21

chango wrote:
06 Feb 2020, 11:16
I have some large text blocks and I want to split then into lines with a set or random amount of words

SO my sudo is

Open textX file
Loop until words remaining is less than 15 (length of string)
Count 15 - 20 spaces (in between word space) String = Words(count)
Add full stop
Carriage return
Loop
Save FileX
the highlighted solution does not add a "full stop" and doesn't select a random amount of words fyi.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Marium0505, mcl, Spikea and 347 guests