• 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: Paul Skinner <email@hidden>
  • Date: Wed, 25 Jun 2003 09:11:41 -0400

On Tuesday, June 24, 2003, at 10:53 PM, Joseph Weaks wrote:

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

Don't go there. just write the most efficient handler you can and use it consistently.

ps
_______________________________________________
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.

References: 
 >Re: Get position of item in list (From: Joseph Weaks <email@hidden>)

  • Prev by Date: Re: Oh-oh, another victim to scripting Mail [SOLVED!]
  • Next by Date: Re: What is the most recordable application in OS X? (and other questions)
  • Previous by thread: Re: Get position of item in list
  • Next by thread: Re: Get position of item in list
  • Index(es):
    • Date
    • Thread