• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Index from list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Index from list


  • Subject: Index from list
  • From: Pier Kuipers <email@hidden>
  • Date: Mon, 19 Feb 2001 12:01:15 +0000

I am trying to find a "clean and quick" way to find out the index of
any item in an unordered list with Vanilla Applescript. Below is the
snippet that I've come up with:

on getListIndex(theItem, theList)
set x to count theList
set p to 1
repeat with i from 1 to x
if theItem = item p of theList then
return p
exit repeat
else
set p to p + 1
end if
end repeat
return p
end getListIndex

set myList to {"Hello", "My Name", "is", "Pier", "Kuipers"}
set myItem to "Pier"

getListIndex(myItem, myList)
-- returns 4 in this case

Is there a neater, or quicker, way to do this? Will this script
result in slow performance if the list is very long? Any advice
greatly appreciated.

Pier.
--
Pier Kuipers
Visual ID
* the Media Asset Management solution *

2 Whitefriars
Aungier Street
Dublin 2
Tel. +353 1 476 7059
Mobile +353 87 294 3063
Fax +353 1 478 1366
ISDN +353 1 602 0754

http://www.visualid.com


  • Follow-Ups:
    • Re: Index from list
      • From: "Serge Belleudy-d'Espinose" <email@hidden>
  • Prev by Date: Re: Keyboard question?
  • Next by Date: Re: Re: Character mangling test
  • Previous by thread: Re: ChatSpeak
  • Next by thread: Re: Index from list
  • Index(es):
    • Date
    • Thread