Re: Stepping through lines in a variable of text
Re: Stepping through lines in a variable of text
- Subject: Re: Stepping through lines in a variable of text
- From: "Marc K. Myers" <email@hidden>
- Date: Sat, 01 Dec 2001 01:37:27 -0500
- Organization: [very little]
>
From: email@hidden
>
Date: Fri, 30 Nov 2001 18:13:55 EST
>
Subject: Stepping through lines in a variable of text
>
To: email@hidden
>
>
I've got a script that reads through a file on the hard-drive, line-by-line:
>
>
repeat
>
set linetoread to read originalfile before return
>
-- do analysis of that line (linetoread) here
>
end repeat
>
>
I need to do the same thing, but reading line-by-line through a global
>
variable of text.
>
>
I'm guessing it would be something like:
>
>
repeat with x = 1 to the number of lines in textvariable
>
set linetoread to line x of textvariable
>
-- do analysis of that line (linetoread) here
>
end repeat
>
>
That's the way I'd do it in Macromedia Director-Lingo - - - how would I do
>
this in AppleScript? It doesn't appear to like the "repeat with x = 1" part.
In AppleScript, paragraphs are elements of strings. They start with the
beginning of the text or the character after the end of the previous
paragraph. They're terminated by a return character or the end-of-text.
set theText to "P1
P2
P3"
repeat with i from 1 to (count paragraphs of theText)
set lineToRead to paragraph i of theText
-- do something with the text
end repeat
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[12/1/01 1:35:24 AM]