Page 1 of 1
What line is it?
Posted: Sun May 20, 2018 12:35 am
by RossG
I have a list field with two items per line..
17 18
22 19
13 21
27 26
I can find the line which item 2 matches
e.g 21 but I then need the line number so that I
can extract item 1 for that line and 3 or 4
lines before and after.
Re: What line is it?
Posted: Sun May 20, 2018 1:18 am
by ClipArtGuy
Here's what I came up with.
Code: Select all
local tSearch
ask "Number to find?"
put it into tSearch
set the itemdelimiter to space
repeat with x = 1 to the number of lines in fld "Your Field"
if (item 2 of line x of fld "Your Field" = tSearch) then
answer (tSearch && "is in line" && x &"."&cr&"Item 1 of line"&&x&&" is" && item 1 of line x of fld "Your Field")
end if
end repeat
Re: What line is it?
Posted: Sun May 20, 2018 2:56 am
by RossG
Thanks for your help ClipArtGuy.
I must remember to use the field and
not the array which populates it (and
is superfluous anyway).
Re: What line is it?
Posted: Sun May 20, 2018 6:45 pm
by jacque
The lineOffset function might be easier, but keep in mind that it will return only the first instance it finds unless you add the second "skip" parameter. Since you want the second item, search for space and the number.
Code: Select all
put lineOffset(space & tNum, fld x) into tLine
That will give you the line number, which you can use to extract word 2, and then add 1 sequentially to get the next 2 lines.
Re: What line is it?
Posted: Mon May 21, 2018 9:28 pm
by dunbarx
What everyone said.
And especially Jacque's comment about the first instance. You ought to write a general purpose handler that extracts all the foundLines in any given search, as well as foundChunk within each. I have been using one forever, and find it an invaluable general purpose gadget that I call from a library stack.
Anyone remember Rinaldi's "fullFind"?
Craig
Re: What line is it?
Posted: Tue May 22, 2018 7:02 am
by mrcoollion