• 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: Offset in list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Offset in list


  • Subject: Re: Offset in list
  • From: Barry Wainwright <email@hidden>
  • Date: Fri, 11 Feb 2005 13:36:40 +0000

On 11/2/05 12:54 pm, "Bastiaan Boertien" <email@hidden>
wrote:

> Hi List
>
> Is there a way to get the offset of an item from a list as number
>
> because we can do it with a string like this
> set theString to "658947123"
>
> offset of "4" in theString
>
> I know how to do it with a repeat but that's to slow
>
> greetings bastiaan

Without OSAXen:

-- Build me a list of random letters
set theletters to characters of "abcdefghijklmnopqrstuvwxyz"
set theList to {}
repeat 100 times
    copy (some item of theletters & some item of theletters & some item of
theletters) as text to end of theList
end repeat

-- get some string to find
set searchString to some item of theList

-- Now find it!
set theDelims to ":" -- SOME UNIQUE VALUE
set AppleScript's text item delimiters to {theDelims}
set theString to theList as string
set AppleScript's text item delimiters to {""}
set shellScript to "echo " & quoted form of theString & ¬
"|awk  ' BEGIN { RS=\"" & theDelims & "\" } /^" & searchString & ¬
"$/ { print  NR}' "
set listItem to (do shell script shellScript) as integer
{searchString, item listItem of theList}


--
Barry



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Offset in list
      • From: Paul Berkowitz <email@hidden>
References: 
 >Offset in list (From: Bastiaan Boertien <email@hidden>)

  • Prev by Date: Re: Offset in list
  • Next by Date: Re: Hotkeys to Snapz Pro or Grab
  • Previous by thread: Re: Offset in list
  • Next by thread: Re: Offset in list
  • Index(es):
    • Date
    • Thread