Re: Removing items from a list
Re: Removing items from a list
- Subject: Re: Removing items from a list
- From: Jason Bourque <email@hidden>
- Date: Tue, 09 Mar 2004 19:38:41 -0500
Hello,
Take a look at this Tids approach. It should be pretty fast.
Thanks,
Jason Bourque
on srRemoveListItemByExactMatch(lList, lItemToRemove)
-- Description:
-- Remove all list items by a single item of the exact match.
-- Case is considered.
-- Capture the current delimiter for AppleScript at the beginning of the
handler
set {lTids, AppleScript's text item delimiters} to {AppleScript's text
item delimiters, ""}
considering case
set AppleScript's text item delimiters to ""
set lList to lList as text
set lList to "" & lList & ""
set AppleScript's text item delimiters to ("" & lItemToRemove &
"")
set lList to every text item of lList
set AppleScript's text item delimiters to ""
set lList to text 5 thru -5 of (lList as text)
set AppleScript's text item delimiters to ""
set lList to every text item of lList
end considering
-- Reset the delimiter for AppleScript to its previous call state
set AppleScript's text item delimiters to lTids
return lList
end srRemoveListItemByExactMatch
On 3/6/04 4:09 PM, "Michelle Steiner" <email@hidden> wrote:
>
This came up on the Applescript newsgroup. Someone wanted to be able
>
to remove all instances of certain items from a list. Here was my
>
solution; I'm sure I'm not the first person to have come up with it.
>
>
set x to {"fu", "foo", "bar", "fu", "foobar", "fubar"}
>
>
-- remove items matching "fu" and "fubar" from x
>
set z to {"fu", "foobar"}
>
set xx to {}
>
repeat with a in x
>
if a is not in z then
>
copy contents of a to end of xx
>
end if
>
end repeat
>
xx
>
>
--> {"foo", "bar", "fubar"}
>
>
Too bad "whose" and the like don't work on lists...
>
>
-- Michelle
_______________________________________________
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.