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