• 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
Re: Snippet to remove an item from a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Snippet to remove an item from a list


  • Subject: Re: Snippet to remove an item from a list
  • From: email@hidden
  • Date: Mon, 9 Jul 2001 12:47:59 EDT

Victor,

Oh yes, it's been done before, and your handler will choke on very long
lists. With a list of 200 items, removing item #177, the following handler is
about 50 times faster. The error handling is failsafe for a CGI, and the code
is line wrap friendly.

on purgeFromList(theList, indexOfThePurged)
copy theList to safelist
try
set x to indexOfThePurged
if x < 1 then return theList
if x = 1 then return (rest of theList)
set coitl to length of theList
if x > coitl then return theList
if x = coitl then
set newlist to (items 1 thru -2 of theList)
else
set newlist1 to (items 1 thru (x - 1) of theList)
set newlist2 to (items (x + 1) thru -1 of theList)
set newlist to newlist1 & newlist2
end if
on error
copy safeList to newlist
end try
return newlist
end purgeFromList

In a message dated 7/8/01 8:50:07 PM, Victor Yee wrote:

>Don't know if this one's been done before, but here's a snippet to remove an
item
>from a list:
>
>on deleFromList(thisListRef, thisIndex)
> if (count of thisListRef) < thisIndex then
> error "Can't remove non-existent item."
> end if
> repeat with i from thisIndex to 2 by -1
> set item i of thisListRef to item (i - 1) of thisListRef
> end repeat
> set contents of thisListRef to rest of thisListRef
>end deleFromList
>
>set x to {"a", "b", "c", "d", "e"}
>set xr to a reference to x
>deleFromList(xr, 3)
>x
>--> {"a", "b", "d", "e"}
>
>Victor


  • Prev by Date: Re: AppleScript -> How to send a text message to a cellularphone
  • Next by Date: count of items in a reference to a list
  • Previous by thread: Re: Snippet to remove an item from a list
  • Next by thread: Re: Snippet to remove an item from a list
  • Index(es):
    • Date
    • Thread