Page 1 of 1

help me with text creator

Posted: 27 Sep 2021, 14:41
by djowdias97
hi, i'm wanting to make a script for example, it takes a list of words from a notepad for example,

house
car
bus

and it adds numbers to the end of each one without repeating for example

house1
car1
bus1

from 1, 0001 to 9999

and saves it again in a new file, would that be possible?

thank you

Re: help me with text creator

Posted: 27 Sep 2021, 14:57
by mikeyww

Code: Select all

count := {}, out := "", new := A_ScriptDir "\new.txt"
ControlGetText, text, Edit1, ahk_exe notepad.exe
For each, line in StrSplit(text, "`r`n")
 count[line] := (0 count[line]) + 1, out .= "`n" line count[line]
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"

Re: help me with text creator

Posted: 27 Sep 2021, 15:11
by djowdias97
the notepad I wanted to say , is to get the notepad keywords from some way , for example C:\Users\admin\Desktop\here.txt

the script works fine, would it be possible to put it in this form?

house1
house2
house3 <- until 9999
car1
car2
car3 <- until 9999
bus1
bus2
bus3 <- until 9999

Re: help me with text creator

Posted: 27 Sep 2021, 15:42
by mikeyww

Code: Select all

word := [], count := {}, out := "", new := A_ScriptDir "\new.txt", max := 9999
ControlGetText, text, Edit1, ahk_exe notepad.exe
For each, item in StrSplit(Trim(text, "`r`n"), "`r`n")
 word.Push(count.HasKey(item) ? "" : item), count[item] := (0 count[item]) + 1
For each, item in word
 Loop, % Min(count[item], max)
  out .= "`n" item A_Index
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"
There's an easier way that someone posted a while back, but I lost track of it.

Re: help me with text creator

Posted: 27 Sep 2021, 15:49
by djowdias97
is there a way to choose which file it will take as keywords? I run the file you wrote me and it creates words, but I don't know where it's getting them,
but for the help I'll thank you, you're a beast!

Re: help me with text creator

Posted: 27 Sep 2021, 15:58
by mikeyww

Code: Select all

; file = %A_ScriptDir%\words.txt ; Change file path as needed
FileSelectFile, file,,, Select a file, Text documents (*.txt)
If (file = "")
 Return
word := [], count := {}, out := "", new := A_ScriptDir "\new.txt", max := 9999
If !FileExist(file) {
 MsgBox, 48, Error, File not found.`n`n%file%
 Return
} Else FileRead, text, %file%
For each, item in StrSplit(Trim(text, "`r`n"), "`r`n")
 word.Push(count.HasKey(item) ? "" : item), count[item] := (0 count[item]) + 1
For each, item in word
 Loop, % Min(count[item], max)
  out .= "`n" item A_Index
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"

Re: help me with text creator

Posted: 27 Sep 2021, 16:07
by djowdias97
mikeyww wrote:
27 Sep 2021, 15:58

Code: Select all

; file = %A_ScriptDir%\words.txt ; Change file path as needed
FileSelectFile, file,,, Select a file, Text documents (*.txt)
If (file = "")
 Return
word := [], count := {}, out := "", new := A_ScriptDir "\new.txt", max := 9999
If !FileExist(file) {
 MsgBox, 48, Error, File not found.`n`n%file%
 Return
} Else FileRead, text, %file%
For each, item in StrSplit(Trim(text, "`r`n"), "`r`n")
 word.Push(count.HasKey(item) ? "" : item), count[item] := (0 count[item]) + 1
For each, item in word
 Loop, % Min(count[item], max)
  out .= "`n" item A_Index
FileRecycle, %new%
FileAppend, % SubStr(out, 2), %new%
Run, "%new%"
well, now I understand the program but it is not numbered as keywords, for example

house1
house12
house123
house1234

Re: help me with text creator

Posted: 27 Sep 2021, 16:17
by mikeyww
It looks like you should step back and provide the exact example that you want, in detail, including both the complete input text and the complete output text. Figure out exactly what you need before you post. The posted script provides output that matches that in your earlier post.

Re: help me with text creator

Posted: 27 Sep 2021, 19:24
by djowdias97
mikeyww wrote:
27 Sep 2021, 16:17
It looks like you should step back and provide the exact example that you want, in detail, including both the complete input text and the complete output text. Figure out exactly what you need before you post. The posted script provides output that matches that in your earlier post.
what I need is to load a notepad with some keywords and for each keyword number from 1 to 9999 at the end of the keyword

example

house1
house2
house3
house9999
bike1
bike2
bike3
bike9999

Re: help me with text creator

Posted: 27 Sep 2021, 19:40
by mikeyww
That's a real example of the exact output? What was the input? What rules have determined your suffix numbers in your example? In other words, how is the suffix number determined?

Re: help me with text creator

Posted: 27 Sep 2021, 19:59
by djowdias97
mikeyww wrote:
27 Sep 2021, 19:40
That's a real example of the exact output? What was the input? What rules have determined your suffix numbers in your example? In other words, how is the suffix number determined?
I simply want any keyword that is in the notepad that I load to be added to the numbers from 1 to 9999 in all the available keywords in the notepad leaving the keyword from 1 to 9999 with no repeats.

Re: help me with text creator

Posted: 27 Sep 2021, 20:18
by mikeyww
I will just ask for an example a third time: what is an exact input file, and the exact output that you would want for it?

Re: help me with text creator

Posted: 28 Sep 2021, 17:46
by djowdias97
I managed to understand the code and it's serving me now, thanks for the help