Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nfcatt

macrumors member
Original poster
May 7, 2006
42
0
Hi All,

Am a newbie to AS and am having trouble trying to do what I hoped would be very easy!

I am trying to search a text file on a line by line basis looking for a string which is midway along the line of text. Each time the string is found I need it to return the first few characters of the line it was found on and then move on checking each subsequent line until the end of the file.

At the end of this I would like to have a variable containing all the matches.

Any examples of how to make the loop work would be greatly appreciated!

Thanks,

Nelson.
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Hi All,

Am a newbie to AS and am having trouble trying to do what I hoped would be very easy!

I am trying to search a text file on a line by line basis looking for a string which is midway along the line of text. Each time the string is found I need it to return the first few characters of the line it was found on and then move on checking each subsequent line until the end of the file.

At the end of this I would like to have a variable containing all the matches.

Any examples of how to make the loop work would be greatly appreciated!

Thanks,

Nelson.

Try something like this...
Code:
set variableStore to ""
set sometext to "some text"
set theparas to the paragraphs of 
set i to 1
repeat the count of theparas times
[INDENT]set tp to paragraph i of sometext
if tp contains "<search text>" then
[INDENT]set variableStore to variableStore & "\n"& items 1 thru 5 of tp[/INDENT]
end if
set i to i+1[/INDENT]
end repeat
variableStore
 

nfcatt

macrumors member
Original poster
May 7, 2006
42
0
Hi,

Thanks again Eraserhead, I found my error once I checked out your script..

Was trying to do it the hard way!! - As usual...

Cheers,

Nelson.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.