• 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: List item number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: List item number


  • Subject: Re: List item number
  • From: has <email@hidden>
  • Date: Tue, 25 Feb 2003 17:28:00 +0000

Steve Suranie wrote:

When a hot folder accepts a file it parses the file name for a certain string then compares that string to a list (array) - {"item1", "item1B", "item2", "item2B", "item3", "item3B"} If the list contains the string is there a way to return where in the list that string appears. For example, using the list above.

Simplest answer:

on offsetInList(lst, val)
repeat with i from 1 to count of lst
if lst's item i is val then return i
end repeat
return 0
end offsetInList

offsetInList({"item1", "item1B", "item2", "item2B", "item3", "item3B"}, "item2")

If comparing text, it'll be subject to whatever considering/ignoring options are in effect at the time, of course. Performance should be quite acceptable as long as the list is small. If time is a problem with larger lists, it may be speeded up with some judicious hacking. There may also be alternative approaches that are significantly faster, albeit with some limitations on the sort of data that can be used. I don't know if there are any osaxen with an offset command for lists, or how one might compare with a vanilla solution; maybe others will know.

has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.

  • Prev by Date: Re: Print ? OSX -> 9.2wUSB HPjet
  • Next by Date: FLAME WAR (was Re: Looking into AppleScript (Was: Re: Scripting Mail:get )
  • Previous by thread: List item number
  • Next by thread: Print ? OSX -> 9.2wUSB HPjet
  • Index(es):
    • Date
    • Thread