• 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: Determining item number matching "x" in a list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining item number matching "x" in a list


  • Subject: Re: Determining item number matching "x" in a list
  • From: John Delacour <email@hidden>
  • Date: Wed, 12 Mar 2003 00:38:33 +0000
  • Mac-eudora-version: 6.0a11

At 12:31 am +0100 12/3/03, Emmanuel wrote:

The loop method may be slow if your script has to perform that task often. For a faster (yet, less direct) method, convert the list into a string, use the Regular Expressions to locate the variable, and then again to evaluate the index of the match.

Here's a way to get the indices of matching items using a loop in perl, which will take no time. I think there's also a direct way to get it, but my perl's rusty this month.



set vList to words of "one two three four three five three"
--> {"one", "two", "three", "four", "three", "five", "three"}
set vSearch to "three"
set my text item delimiters to ASCII character 10
set vString to vList as string
set my text item delimiters to ASCII character 10
do shell script "perl -e '
$string = qq~" & vString & "~ ; $search = qq~" & vSearch & "~;
for (split $/, $string){
$n++ ;
m~$search~i and print qq~$n$/~
}'"
paragraphs of result
_______________________________________________
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: 
 >Determining item number matching "x" in a list (From: Steve Cunningham <email@hidden>)
 >Re: Determining item number matching "x" in a list (From: Emmanuel <email@hidden>)

  • Prev by Date: Re: assistance with script, part 2
  • Next by Date: Re: assistance with script, part 2
  • Previous by thread: Re: Determining item number matching "x" in a list
  • Next by thread: Re: Determining item number matching "x" in a list
  • Index(es):
    • Date
    • Thread