Re: it's...
Re: it's...
- Subject: Re: it's...
- From: "Arthur J Knapp" <email@hidden>
- Date: Mon, 16 Apr 2001 11:34:32 -0400
>
Subject: it's...
>
Date: Sun, 15 Apr 2001 05:38:41 -0700
>
From: Richard 23 <email@hidden>
>
Whenever writing a script that manipulates text I'm often in need of
>
repeated strings: spacers, dashed lines among others.
>
I have a handler that takes a string and a length as arguments and returns
>
on RepeatString of theStr for theLen
>
without elaborating too much on RepeatString, here's some quick uses:
>
>
RepeatString of "12" for 7
>
--> "1212121"
>
However in order to for a property to make use of the handler during
>
compilation, the handler has to preceed it in the script, which, for
>
reasons of style, I don't particularly like.
I have occationally employed what I call a compile-time-initializer,
(I like long made-up names), like this:
property CompObj : load script file "blah:blah:CompileHelper"
property String01 : RepeatString("12", 7) of CompObj
property String02 : RepeatString("6", 3) of CompObj
etc...
After these properties have been set, there may be no runtime need
for CompObj, so we "zero" it out it reclaim it's memory:
on run
set CompObj to missing value
And if you are a really clever person, you might even find a runtime use
for the now empty property.
>
This method is less expensive than the other two and can build up fairly
>
large strings in a single line without much difficulty:
>
"" & [it, it]'s [it, it]'s [it, it]'s [it, it] of " "
>
" "'s [it, it, it, it]'s [it, it, it, it] as string
>
-- 160 spaces
>
>
"" & [it, it]'s [it, it, it, it, it, it] of " "
>
-- 120 spaces
This is clever stuff. :)
For my own purposes, a small handler at the top of a script to
assist in property-initializing wouldn't be a problem:
on rep(str, len)
set lst to {}
repeat len times
set end of lst to str
end repeat
return ("" & lst)
end rep
property spc : rep("^", 100)
spc
Or...
on rep(str, len)
str
repeat (len - 1) times
result & str
end repeat
end rep
property spc : rep("^", 100)
spc
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.mainevent.com