Re: Two Questions - RemoveListItem(x, theList)
Re: Two Questions - RemoveListItem(x, theList)
- Subject: Re: Two Questions - RemoveListItem(x, theList)
- From: JollyRoger <email@hidden>
- Date: Sun, 11 Feb 2001 17:30:22 -0600
on 2/11/2001 2:13 PM, Byron Peterson at email@hidden wrote:
>
What is the fastest way to remove an item from a large list (the list I9m
>
working with has about 3000 items in it). The item I need to remove is in
>
the middle of the list and it isn9t the same item every time?
Not sure if this is the absolute fastest; but it's vanilla AppleScript, and
quick enough for my purposes. I've been using this handler for a few years:
on RemoveListItem(x, theList)
-- removes any item from a list
set x to (x as number)
if x < 1 then return theList
set numItems to count of items in theList
if numItems is 1 then return {}
if x > numItems then return theList
if x = 1 then
set newList to (items 2 thru -1 of theList)
else if x = numItems then
set newList to (items 1 thru -2 of theList)
else
set newList to (items 1 thru (x - 1) of theList) & (items (x + 1)
thru -1 of theList)
end if
return newList
end RemoveListItem
(Watch for carriage returns and mangled characters courtesy of the list
server.)
HTH
JR