Re: Offset in list
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