The script as proposed by
shadowslash will definitely work, but can be optimized. This should be faster for longer texts:
Code: Select all
on mouseUp
repeat for each line theLine in myVariable
put the first word of theLine & return after theFirstWordList
end repeat
-- strip the trailing return
delete the last char of theFirstWordList
end mouseUp
When you use a
repeat for each line loop, the engine will go through the data one line at a time, and can remember where it's at in the variable.
If you use a
repeat with theIndex = 1 to the number of lines loop, the engine has to start counting lines again from the very beginning of the text, in order to find
line theIndex of the data.
Also, when you use a
repeat with loop, it's faster to evaluate the
end value just once - otherwise the engine may have to recount every time, just to make sure it hasn't gone too far. So it's faster to:
Code: Select all
put the number of lines in theVariable into theCount
repeat with theIndex = 1 to theCount
...
end repeat
Anyway, using
repeat for each can improve performance dramatically, and it's best to pick up on these peculiarities of the language as quickly as possible
Jan Schenkel.