Re: A problem when reading/writing to a text file
Re: A problem when reading/writing to a text file
- Subject: Re: A problem when reading/writing to a text file
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 04 Jan 2002 08:32:21 -0500
on 02-02-06 6:12 AM, jason batt at email@hidden wrote:
>
Heres my problem -
>
How can I read only specific text from a text file, ie only the text
>
between two markers eg "/*" and "*/" and then write this text into a
>
newly created text file with the same name as the original at a
>
differant location on my hardrive. (Bearing in mind that there are
>
multiple sets of markers in each text file as its the comments from some
>
code)
Read the instructions for the Standard Additions Read/Write commands, in the
Scripting Additions Guide, available at the Apple Web site. It contains very
complete instructions and lots of sample statements -- including a complete
database manager in AppleScript.
Basically, to read specific text, you open the text file, then read it
"until" your chosen delimiter in a repeat loop until you get an end-of-file
error. To snag the text between the markers, you'll have to make the repeat
loop a little more complex, reading and discarding text you don't want. The
read command updates the current file pointer every time you read.
Writing these text snippets to another text file in lines could be done in a
repeat loop, as well, but it would probably be better to write each line you
wanted to snag, within the read loop. Write a carriage return after each
text snippet.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont