• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Stepping through lines in a variable of text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Stepping through lines in a variable of text


  • Subject: Stepping through lines in a variable of text
  • From: Kai Edwards <email@hidden>
  • Date: Sat, 01 Dec 2001 17:40:10 +0100

on Fri, 30 Nov 2001 18:13:55 EST, email@hidden wrote:

> 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.

As a relative newbie myself, I hesitate to offer a possible solution -
especially in such distinguished and knowledgeable company as is frequently
found on this list.

However, it seems to me that there are a couple of jobs to do:
1) Establish the number of lines in the text variable
2) Separate each line of text for further analysis (hence the repeat loop)

There are probably better ways counting lines of text, but I can only come
up with using AppleScript's text item delimiters to do this reasonably
quickly. (Don't forget to reinstate the default delimiters once the job is
done.)

The only problem I can see with your repeat loop is the use of Lingo's <=>
rather than AppleScript's <from> in your counter specification.

So, while I'm sure someone will come up with a better suggestion, you could
just try modifying your script to read something like this:

set {TID, text item delimiters} to {text item delimiters, return}
repeat with x from 1 to (count text items in textvariable)
set linetoread to text item x of textvariable
-- do analysis of that line (linetoread) here
end repeat
set text item delimiters to TID

--

**********************************
Kai Edwards Creative Resources
1 Compton Avenue Brighton UK
Telephone +44 (0)1273 326810
**********************************


  • Prev by Date: scripting Graphic converter
  • Next by Date: Re: Stepping through lines in a variable of text
  • Previous by thread: Re: Stepping through lines in a variable of text
  • Next by thread: Re: Stepping through lines in a variable of text
  • Index(es):
    • Date
    • Thread