Split a text file and save it into paragraphs in other text files Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
crypter
Posts: 90
Joined: 15 Dec 2020, 09:57

Split a text file and save it into paragraphs in other text files

02 Aug 2021, 18:32

I need a script that can split text from a text file into other text files for each paragraph. Each paragraph should be saved as a text file
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Split a text file and save it into paragraphs in other text files

02 Aug 2021, 19:06

crypter wrote:
02 Aug 2021, 18:32
I need a script that can split text from a text file into other text files for each paragraph. Each paragraph should be saved as a text file
what separates each paragraph?
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Split a text file and save it into paragraphs in other text files

02 Aug 2021, 20:57

one method

Code: Select all

test =
(
I need a script that can split text from
a text file into other text files for
each paragraph. Each paragraph should
be saved as a text file

Is it by any way possible?
Even to avoid script
error after same 2nd key use
I need can split text from
)
array := strsplit(test, "`n`n")
loop, % array.maxIndex()
	MsgBox, % array[A_Index] ; you could replace with FileAppend, % array[A_Index], % "file" a_index ".txt"
ExitApp
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Split a text file and save it into paragraphs in other text files

02 Aug 2021, 21:57

I suggest the following change to handle files that have both CR+LF (`r`n) characters between each line instead of just a LF (`n) character:

Code: Select all

array := strsplit(strreplace(test, "`r"), "`n`n")
crypter
Posts: 90
Joined: 15 Dec 2020, 09:57

Re: Split a text file and save it into paragraphs in other text files

03 Aug 2021, 10:07

this is good but i need it to read from a text file and save as text files
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: Split a text file and save it into paragraphs in other text files  Topic is solved

03 Aug 2021, 10:37

from 'AHKStudent' and 'boiler'
( AHKStudent used the variable 'test' for quick testing )

Code: Select all

f1=%a_scriptdir%\hh.txt   ;--- <<< here is the text
fileread,aa,%f1%
array := strsplit(strreplace(aa, "`r"), "`n`n")
loop, % array.maxIndex()
   FileAppend, % array[A_Index], % "file" a_index ".txt"    ;-- write to file in a_scriptdir\file1.txt ... \file2.txt  ... etc
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 107 guests