Find lines in var with "word" then output to new var? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
TheTrueKey
Posts: 6
Joined: 15 Apr 2017, 15:37

Find lines in var with "word" then output to new var?

15 Apr 2017, 21:11

Hey all,

How would you go about finding lines in a var that contain "word" then output those lines to a new var?

Example:

Find and output lines with "2222"
C:\folder\folder\asdf-1111-file1.txt
C:\folder\folder\asdf-1111-file2.txt
C:\folder\folder\asdf_2222-file1.txt
C:\folder\folder\asdf_2222-file2.txt
C:\folder\folder\asdf3333-file1.txt
C:\folder\folder\asdf3333-file2.txt

Output
C:\folder\folder\asdf_2222-file1.txt
C:\folder\folder\asdf_2222-file2.txt

Thanks
Last edited by TheTrueKey on 16 Apr 2017, 06:07, edited 1 time in total.
Xeno234
Posts: 71
Joined: 24 Mar 2017, 18:14

Re: Find lines in var with "word" then output to new var?  Topic is solved

15 Apr 2017, 22:25

Code: Select all

in =
(
C:\folder\folder\asdf-1111-file1.txt
C:\folder\folder\asdf-1111-file2.txt
C:\folder\folder\asdf_2222-file1.txt
C:\folder\folder\asdf_2222-file2.txt
C:\folder\folder\asdf3333-file1.txt
C:\folder\folder\asdf3333-file2.txt
)
arr := strsplit(in, "`n")
for i, v in arr
	if instr(v, "2222")
		out .= out ? "`n" v : v
msgbox % out
return
TheTrueKey
Posts: 6
Joined: 15 Apr 2017, 15:37

Re: Find lines in var with "word" then output to new var?

15 Apr 2017, 23:31

Hey Xeno that works great thanks for the help! I think I understand most of it but if you get a chance could you do a run down on the logic.

How can I use a var in place of 2222 or SearchString. I tried to insert the var a few different ways but no dice. "%asdf%", "asdf", %asdf%, asdf .etc
Xeno234
Posts: 71
Joined: 24 Mar 2017, 18:14

Re: Find lines in var with "word" then output to new var?

15 Apr 2017, 23:50

Code: Select all

inputbox, str,, String to search for
in =
(
C:\folder\folder\asdf-1111-file1.txt
C:\folder\folder\asdf-1111-file2.txt
C:\folder\folder\asdf_2222-file1.txt
C:\folder\folder\asdf_2222-file2.txt
C:\folder\folder\asdf3333-file1.txt
C:\folder\folder\asdf3333-file2.txt
)
arr := strsplit(in, "`n")
for i, v in arr
	if instr(v, str)
		out .= out ? "`n" v : v
msgbox % out
return
TheTrueKey
Posts: 6
Joined: 15 Apr 2017, 15:37

Re: Find lines in var with "word" then output to new var?

16 Apr 2017, 00:00

My var was set to a missing value, so it was working. Thanks Xeno

Return to “Ask For Help”

Who is online

Users browsing this forum: _______E_______, aurafyyy, boiler, edgedancer, Google [Bot], hasantr, mikeyww, Smile_, sobuj53 and 63 guests