Re: Determining item number matching "x" in a list
Re: Determining item number matching "x" in a list
- Subject: Re: Determining item number matching "x" in a list
- From: Emmanuel <email@hidden>
- Date: Wed, 12 Mar 2003 19:45:49 +0100
At 3:12 PM -0700 11/03/03, Ivan Andrus wrote:
offset of "b" in (theList as text) / length_of_each_item
Pushing further Ivan's suggestion, and as by coincidence I just
needed such a handler today, I submit below a plain-vanilla short
handler that retrieves the rank of a given item in a list of strings.
The strings should not contain a Carriage Return character. The
handler will retrieve only the first hit if there are several.
------------------------------
on IndexOfItem(theItem, theList)
set {savedTID, text item delimiters} to {text item delimiters, return}
set theList to return & theList & return
set text item delimiters to savedTID
set theOffset to offset of (return & theItem & return) in theList
if theOffset is 0 then return 0
-1 + (count paragraphs of (text 1 thru theOffset of theList))
end IndexOfItem
IndexOfItem("Bastia", {"AC Ajaccio", "Auxerre", "Bastia", "Bordeaux"})
--> 3
IndexOfItem("Basti", {"AC Ajaccio", "Auxerre", "Bastia", "Bordeaux"})
--> 0
------------------------------
There is no built-in size limit that I know, but I did not test much
(I'm using it with 20 items ...)
Emmanuel
_______________________________________________
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.