powersplit (was Re: Parent property & load script - info)
powersplit (was Re: Parent property & load script - info)
- Subject: powersplit (was Re: Parent property & load script - info)
- From: email@hidden
- Date: Fri, 2 Feb 2001 01:45:04 EST
In a message dated 2/1/01 9:58:04 PM, Richard Morton wrote:
>
The discussion here early last month on using the inheritance of the
>
parent property as a means of making sub routine handlers available
>
without the need for 'tell' or 'of' was *most* useful for me. Thanks
>
everybody!
I knew I had missed something important while unsubscribed for several
months! I suppose this means my response to Bill Planey needs some
modification. I always thought parents spawned children, but now it seems
that children lay claim to parents. This could prove very useful.
In that vein, here's a handler for the parents. Perl has the "split" command.
Now Applescript has the "powersplit" command. Powersplit allows a string to
be converted to a list of lists of lists (of lists, etc. - it's
reentrant/recursive) based on a variable number of splitting strings.
set x to powersplit("a=1&b=2&c=3", {"&", "="})
--> {{"a","1"}, {"b","2"}, {"c","3"}}
--------------------
on powersplit(src, delimList)
if length of delimList is equal to 1 then
set srcAsList to {}
try
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to (item 1 of delimList)
as string
set srcAsList to (text items of src) as list
set AppleScript's text item delimiters to oldDelims
on error
set AppleScript's text item delimiters to oldDelims
end try
return srcAsList
else
set linesAsList to {}
set srcAsList to my powersplit(src, (item 1 of delimList) as string)
repeat with aLine in srcAsList
set aLineAsList to my powersplit(aLine, (rest of delimList))
copy aLineAsList to end of linesAsList
end repeat
return linesAsList
end if
end powersplit
---------------------
Enjoy!
Jeff Baumann
email@hidden
www.linkedresources.com
Comparing MHz between the G4 and Pentium is like comparing the popular vote
between Bush and Gore; it's interesting, but it isn't what matters.