• 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: Kai <email@hidden>
  • Date: Tue, 24 Jun 2003 21:12:15 +0100

on Tue, 24 Jun 2003 10:14:52 +0200, Emmanuel <email@hidden> wrote:

> At 4:51 AM +0100 24/06/03, Kai wrote:

>>'Fraid not, Joe. If your list is a short one, stick with the repeat loop.
>>For long lists, you might try a tid-based approach:
>
> Once there was a thread on that topic...

Right. I tried (briefly) to recall the subject line of that thread but
initially failed. Now I recall that it was something like "Determining item
number matching "x" in a list". Joe may like to check the archives for this.

> ...and if I remember correctly the most efficient algorithm was found to be
the following.
>
> -------------------------------------------
> on NGELItemIndexOfString(theString, theList)
> set theList to return & theList & return
> try
> -1 + (count paragraphs of (text 1 thru (offset of (return & theString &
> return) in theList) of theList))
> on error
> return 0
> end try
> end NGELItemIndexOfString
> -------------------------------------------
>
> NGELItemIndexOfString("too", {"wan", "too", "tree", "for"})
> -- 2

Not using 'offset' (which isn't that fast) - but I believe a later version
dispensed with the offset command.

Perhaps it's worth pointing out that tid-based methods rely on a list
containing only string values.

Lists containing 4000+ items may also result in a stack overflow error. (An
oft-quoted figure is 4060, though I believe this may fluctuate according to
what else is in the stack at the time).

Obviously, care should also be taken with the above approach if there's a
chance that any strings might contain return characters.

--
Kai
_______________________________________________
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: Selection in Safari
  • Next by Date: Re: Script Editor 2.0 (beta II)
  • Previous by thread: Re: Get position of item in list
  • Next by thread: Re: Get position of item in list
  • Index(es):
    • Date
    • Thread