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
Find lines in var with "word" then output to new var? Topic is solved
-
- Posts: 7
- Joined: 15 Apr 2017, 15:37
Find lines in var with "word" then output to new var?
Last edited by TheTrueKey on 16 Apr 2017, 06:07, edited 1 time in total.
Re: Find lines in var with "word" then output to new var? Topic is solved
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
-
- Posts: 7
- Joined: 15 Apr 2017, 15:37
Re: Find lines in var with "word" then output to new var?
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
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
Re: Find lines in var with "word" then output to new var?
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
-
- Posts: 7
- Joined: 15 Apr 2017, 15:37
Re: Find lines in var with "word" then output to new var?
My var was set to a missing value, so it was working. Thanks Xeno
Who is online
Users browsing this forum: Bing [Bot], Spawnova and 263 guests