Re: Snippet to remove an item from a list
Re: Snippet to remove an item from a list
- Subject: Re: Snippet to remove an item from a list
- From: Bryan <email@hidden>
- Date: Tue, 10 Jul 2001 12:55:27 -0400
- Organization: Apex Radiology
THERE IS ALWAYS THE OSAX ALTERNATIVE
The Satimage OSAX that comes with Smile (it's free)
includes the command:
suppress item : delete an item from a list or a record.
suppress item anything -- the rank or key of the item.
Use quotes around custom properties, and also around 4-characters
codes.
(If you don't know what this means, you don't need it).
from anything -- a list or a record
Result : list or record --
The usage in your example would be:
suppress item x from lst
I use this frequently and have never had any problems with it.
This is very flexible and can be used with records to delete a key;
or with the 'get offset' commands to find and delete a text item from a
list.
Bryan Kaufman
Arthur J Knapp wrote:
>
> Subject: Re: Snippet to remove an item from a list
>
> Date: Mon, 9 Jul 2001 08:38:04 -0700
>
> From: Michelle Steiner <email@hidden>
>
>
> On 7/9/01 7:24 AM, Arthur J Knapp <email@hidden> wrote:
>
>> Here is the more traditional AppleScript technique:
>
>
> Alternatively (slightly modifying Arthur's script):
>
>
>
> on DeleteAt(lst, x)
>
> tell the lst
>
> if (x = 1) then
>
> return the rest
>
> else if (x = the length) then
>
> return items 1 thru -2
>
> else
>
> return (items 1 thru (x - 1)) & ,
>
> (items (x + 1) thru -1)
>
> end if
>
> end tell
>
> end DeleteAt
>
>
Allow me to be even more alternative:
>
>
on DeleteAt(lst, x)
>
tell lst to if x = 1 then
>
rest
>
else if (x = length) then
>
items 1 thru -2
>
else
>
(items 1 thru (x - 1)) & (items (x + 1) thru -1)
>
end if
>
end DeleteAt
>
>
Here are some new creations:
>
>
on InsertAt(lst, x, val)
>
tell lst to if x = 1 then
>
{val} & it
>
else if x > length then
>
it & {val}
>
else
>
items 1 thru (x - 1) & {val} & items x thru -1
>
end if
>
end InsertAt
>
>
on IndexOf(lst, itm)
>
set x to 1
>
tell no & lst to if {itm} is in it then repeat until item x = itm
>
set x to x + 1
>
end repeat
>
x - 1
>
end IndexOf
>
>
Arthur J. Knapp
>
http://www.stellarvisions.com
>
mailto:email@hidden
>
>
Hey, check out:
>
http://www.LateNightSW.com
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users