• 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: Paul Berkowitz <email@hidden>
  • Date: Fri, 11 Feb 2005 08:33:59 -0800

On 2/11/05 5:36 AM, "Barry Wainwright" <email@hidden> wrote:

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

But it does use an osax - 'do shell script'. Did you mean "no 3rd-party
osax", Barry? What do you think of Emmanuel's method, offered by jj? It also
uses an osax - 'offset' - but is a bit simpler.
>
> -- 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}


--
Paul Berkowitz


 _______________________________________________
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:
    • Slightly OT: InDesign cells \ tables
      • From: Bill Planey <email@hidden>
References: 
 >Re: Offset in list (From: Barry Wainwright <email@hidden>)

  • Prev by Date: Re: Hotkeys to Snapz Pro or Grab
  • Next by Date: Quoting
  • Previous by thread: Re: Offset in list
  • Next by thread: Slightly OT: InDesign cells \ tables
  • Index(es):
    • Date
    • Thread