PDA

View Full Version : Applescript help




nfcatt
Mar 17, 2007, 12:27 PM
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
Mar 17, 2007, 04:24 PM
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...

set variableStore to ""
set sometext to "some text"
set theparas to the paragraphs of
set i to 1
repeat the count of theparas times
set tp to paragraph i of sometext
if tp contains "<search text>" then
set variableStore to variableStore & "\n"& items 1 thru 5 of tp
end if
set i to i+1
end repeat
variableStore

nfcatt
Mar 18, 2007, 03:40 AM
Thanks, will try it out..

Nelson.

nfcatt
Mar 18, 2007, 09:26 AM
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.