• 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: Delete an Item from a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delete an Item from a list


  • Subject: Re: Delete an Item from a list
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 03 Jun 2004 11:59:05 -0700

On 6/3/04 11:27 AM, "Steven Valenti" <email@hidden> wrote:

> I want to manipulate a list by taking some items out. I have read that
> you can't delete items from a list. Does anyone have another way of
> doing this besides the way I come up with here? Thanks
>
> set MyList to {"Item-1", "Item-2", "Item-3"}
> set SubtractItem to {"Item-2"} --Items I want to take out
> set AdjustedList to {}
> repeat with i in MyList
> if i is not in SubtractItem then
> copy i as string to end of AdjustedList
> end if
> end repeat
>
> AdjustedList --result {"Item-1", "Item-3"}

That's basically it. :-( You can improve performance by using 'set' rather
than copy, avoid an unnecessary coercion to text and still get values (not
'item 1 of ...') into the new list, and most significant with lists longer
than about 100 items, use a real 'my' if these lines are at the "top level"
of a script or MyList is a global. Otherwise, in a handler, you can use a
"Serge" script object to do the same - ask if interested.



set MyList to {"Item-1", "Item-2", "Item-3"}
set SubtractItem to {"Item-2"} --Items I want to take out
set AdjustedList to {}
repeat with i from 1 to (count MyList)
set anItem to item i of my MyList
if {anItem} is not in SubtractItem then
set end of AdjustedList to anItem
end if
end repeat
AdjustedList
--> {"Item-1", "Item-3"}


--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Delete an Item from a list (From: Steven Valenti <email@hidden>)

  • Prev by Date: Delete an Item from a list
  • Next by Date: Re: JPEG compression factor via AS
  • Previous by thread: Delete an Item from a list
  • Next by thread: Re: Delete an Item from a list
  • Index(es):
    • Date
    • Thread