Re: List item number
Re: List item number
- Subject: Re: List item number
- From: has <email@hidden>
- Date: Tue, 25 Feb 2003 17:28:00 +0000
Steve Suranie wrote:
When a hot folder accepts a file it parses the file name for a
certain string then compares that string to a list (array) -
{"item1", "item1B", "item2", "item2B", "item3", "item3B"} If the
list contains the string is there a way to return where in the list
that string appears. For example, using the list above.
Simplest answer:
on offsetInList(lst, val)
repeat with i from 1 to count of lst
if lst's item i is val then return i
end repeat
return 0
end offsetInList
offsetInList({"item1", "item1B", "item2", "item2B", "item3",
"item3B"}, "item2")
If comparing text, it'll be subject to whatever considering/ignoring
options are in effect at the time, of course. Performance should be
quite acceptable as long as the list is small. If time is a problem
with larger lists, it may be speeded up with some judicious hacking.
There may also be alternative approaches that are significantly
faster, albeit with some limitations on the sort of data that can be
used. I don't know if there are any osaxen with an offset command for
lists, or how one might compare with a vanilla solution; maybe others
will know.
has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.