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 00:40:56 +0100
At 3:12 PM -0700 11/03/03, Ivan Andrus wrote:
At 03:10 PM 3/11/2003 -0500, you wrote:
I wonder if there is some trivial way to do this without writing a repeat
loop that cycles through every value of the list looking for a match:
I have a list, theList = {"a","b","c","etc"} and I want to know the item
number of the item that matches a variable x. I need something like
"get the item number of x in theList"
which returns a if x = "a", 2 if x = "b" etc.
Did I miss a page in the manual :-)
If all the items are of the same length then you can coerce it to
text and use offset. Other than that I don't know how to do it
easily.
offset of "b" in (theList as text) / length_of_each_item
Granted this won't work in most cases, but you never know when it might.
If the items are not the same length (but, still, they must not
include a return character), you can coerce the list to text (set the
text item delimiters to return first), then use "offset" (with return
& x & return) to get the character index of the match, then "text i
thru j" to chop the string at that offset, and finally count the
paragraphs of the substring with "count paragraphs".
I don't know whether Regular Expressions are any better than that
plain vanilla method. I feel like the basic string features of
AppleScript ("text i thru j", "count paragraphs") are rather fast and
reliable.
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.