• 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
Re: Get position of item in list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Get position of item in list


  • Subject: Re: Get position of item in list
  • From: Joseph Weaks <email@hidden>
  • Date: Tue, 24 Jun 2003 21:53:31 -0500

These have all been some very wordy solutions. How does one gauge when the simple repeat I'm using is not efficient? A list of 20 items, 50 items, 100 items? Maximum length of each string in the list of 50 characters, 100 characters, 500 characters?

on getPosition(theString, theList)
if theString is in theList then
repeat with x from 1 to (count text items of theList)
if (text item x of theList) starts with theString then
return x
end if
end repeat
else
return 0
end if
end getPosition

getPosition("for", {"wan", "too", "tree", "for"})
-- 4

("Starts with" suits my current purpose, only returning the first match.)
Cheers,
Joe Weaks
_______________________________________________
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.

  • Follow-Ups:
    • Re: Get position of item in list
      • From: Paul Skinner <email@hidden>
References: 
 >Re: Get position of item in list (From: Kai <email@hidden>)

  • Prev by Date: Re: Selection in Safari
  • Next by Date: Re: Selection in Safari
  • Previous by thread: Re: Get position of item in list
  • Next by thread: Re: Get position of item in list
  • Index(es):
    • Date
    • Thread