• 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 04:51:38 +0100

on Mon, 23 Jun 2003 14:12:32 -0500, Joseph Weaks <email@hidden> wrote:

> I know how to do this with a repeat loop, but surely there's a syntax I
> can't figure out for
>
> property: myList: {"foo","bar"}
>
> set foobar to the position of "bar" in myList

'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:

==============================

property d : ASCII character 1
property mylist : {"a", "much", "longer", "list", "than", "before"}

to getPosition of i from l
if i is not in l then return 0
set {tid, text item delimiters} to {text item delimiters, d}
set {r, text item delimiters} to {d & l & d, d & i & d}
set {{r}, text item delimiters} to {r's text items, d}
set {{number:r}, text item delimiters} to {r's text items, tid}
r
end getPosition

getPosition of "longer" from mylist
--> 3

==============================

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

  • Follow-Ups:
    • Re: Get position of item in list
      • From: Emmanuel <email@hidden>
  • Prev by Date: Re: The Name Game
  • Next by Date: Re: FileMaker styled text [part 1 of 2]
  • Previous by thread: Get position of item in list
  • Next by thread: Re: Get position of item in list
  • Index(es):
    • Date
    • Thread