• 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
it's...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

it's...


  • Subject: it's...
  • From: Richard 23 <email@hidden>
  • Date: Sun, 15 Apr 2001 05:38:41 -0700

I haven't posted in awhile so thought it was time to post something odd.

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
a string of the requested length repeating the input string as many
times as is necessary to produce the string, something like this:

-- ---------------------------------------------------------
-- Preprocessed by Convert Script 1.0d5
-- ---------------------------------------------------------
-- author: Richard 23, date: Sunday, April 15, 2001
-- ---------------------------------------------------------
on RepeatString of theStr for theLen
theStr
if result /= "" and result's length < theLen and theLen > 0 then
repeat while result's length < theLen
result & result
end repeat
if result's class = string then
result's text 1 thru theLen
else
result's items 1 thru theLen
if class of result's first item /= list then
result as string
else
result
end if
end if
else
""
end if
-- inline result
end RepeatString
-- ---------------------------------------------------------

without elaborating too much on RepeatString, here's some quick uses:

RepeatString of "12" for 7
--> "1212121"

RepeatString of {"12"} for 7
--> "12121212121212"

RepeatString of {{"12"}} for 7
--> "{{"12"}, {"12"}, {"12"}, {"12"}, {"12"}, {"12"}, {"12"}}


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've also tried run script which works but I don't like it either:

property spc: run script "tell \" \" to get it & it & it & it"

So I came up with another way to do it which requires neither a handler
nor a run script statement.

This method is less expensive than the other two and can build up fairly
large strings in a single line without much difficulty:

I thought I understood the math behind this silly method until I started
experimenting with it. I'll just show a number of examples and either
let someone else explain it or let this thread pass on into obscurity.


"" & [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

"" & [it]'s [it, it, it, it, it, it, it] of " "
-- 70 spaces

"" & [it, it]'s [it, it] of " "
-- 40 spaces

"" & [it, it, it]'s [it, it, it] of " "
-- 90 spaces

"" & [it, it, it]'s [it, it, it]'s [it, it, it] of " "
-- 270 spaces

"" & [it, it, it, it]'s [it, it, it, it]'s [it, it, it, it] of "
"
-- 640 spaces

NOTE: the quoted string is 10 spaces, and the square brackets are used
only as a alternative to braces which I have seen too many of lately.
And no, I'm not an orthodontist.

R23


  • Prev by Date: Re: Coerce String to Handler Name?
  • Next by Date: Scripting Palm Desktop?
  • Previous by thread: Re: Coerce String to Handler Name?
  • Next by thread: Re: it's...
  • Index(es):
    • Date
    • Thread