Re: How to get parameter item of a string in a list
Re: How to get parameter item of a string in a list
- Subject: Re: How to get parameter item of a string in a list
- From: Emmanuel <email@hidden>
- Date: Mon, 16 May 2005 20:57:18 +0200
At 2:39 PM -0400 5/16/05, Gary (Lists) wrote:
"Patrik B." wrote:
Hi,
I have a list of strings
(lets say five, "Hi", "bye", "good morning", "Tschau", "Hello world") and I
want the number of the item I selected (lets say I selected item "good
morning") In my example it would be 3. How do I get this number so that I
can pass it to a variable so that I can delete it from a list using a
removeItem handler. etc.?
set myList to {"hi", "bye", "allo", "au revoir"}
set phrase to choose from list myList -- returns a list, eg. {"allo"}
set phrase to item 1 of phrase -- a string "allo"
repeat with i from 1 to (count myList)
if item i of myList is phrase then return i
end repeat
--> 3
Excellent!
And if speed does not scare you:
on IndexOfItem(theItem, theList)
set od to tid(return)
set theList to return & theList & return
tid(od)
try
-1 + (count paragraphs of (text 1 thru (offset of
(return & theItem & return) in theList) of theList))
on error
return 0
end try
end IndexOfItem
which uses:
on tid(x)
set y to applescript's text item delimiters
set applescript's text item delimiters to x
return y
end tid
Emmanuel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden