Edit text lines

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joaocassis
Posts: 4
Joined: 10 Aug 2018, 08:59

Edit text lines

10 Aug 2018, 09:07

Hello, I'm totally new to scripting so I need some help here.
I'm trying to import some recipes to a webapp, however the simple copy and paste method don't work.

Here is the original text:

Carrot
3
Garlic
6 cloves
...etc

I want to turn it into:

3 Carrot
6 cloves Garlic

Basically cut the first line and paste it after the following line.
Is it possible?

Thank you for your help
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Edit text lines

10 Aug 2018, 09:54

Code: Select all

sample = 
(
Carrot
3
Garlic
6 cloves
)

Lines := StrSplit(sample, "`n", "`r")

while(Lines.Count())
{
	food := Lines.RemoveAt(1)
	amount := Lines.RemoveAt(1)
	result .= Format("{} {}`n", amount, food)
}

MsgBox % result
joaocassis
Posts: 4
Joined: 10 Aug 2018, 08:59

Re: Edit text lines

10 Aug 2018, 10:44

I ran the script with the text file opened and nothing happened.
garry
Posts: 3764
Joined: 22 Dec 2013, 12:50

Re: Edit text lines

10 Aug 2018, 10:56

you need :
fileread,sample,myfile.txt

Code: Select all

sampl1 = 
(
Carrot
3
Garlic
6 cloves
)

f1=%a_scriptdir%\test55.txt
ifnotexist,%f1%
   fileappend,%sampl1%,%f1%
;--------- end test -----------------
   
fileread,sample,%f1%    ;- <<< read your file

Lines := StrSplit(sample, "`n", "`r")
while(Lines.Count())
{
	food := Lines.RemoveAt(1)
	amount := Lines.RemoveAt(1)
	result .= Format("{} {}`n", amount, food)
}
MsgBox % result
return
joaocassis
Posts: 4
Joined: 10 Aug 2018, 08:59

Re: Edit text lines

10 Aug 2018, 12:26

Thank you that worked perfectly!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 333 guests