Re: Newbie, every word where it contains "ox"
Re: Newbie, every word where it contains "ox"
- Subject: Re: Newbie, every word where it contains "ox"
- From: Mr Tea <email@hidden>
- Date: Thu, 08 Aug 2002 14:20:15 +0100
This from Steen - dated 8-8-02 11.41 am:
>
I try to get words that contains "ox" from a string.
>
>
I get an error (-1728)
... because your script is trying to compare a string with a list.
>
Do I need to make a loop, how do I do it?
Yes. Here's one way...
set myStringList to every word of "the fox oxon can count 1 2 3 and he love
nox"
set oxWords to {}
repeat with theWord in myStringList
if theWord contains "ox" then
set end of oxWords to theWord as string
end if
end repeat
oxWords
--> {"fox", "oxon", "nox"}
You also tried to do some additional word checking like this:
>
if a is not equal to "fox" then
>
beep
>
end if
>
if a is equal to "nox" then
>
beep
>
end if
Unfortunately, there's a problem with using beeps, because they play
concurrently instead of sequentially - so if the value of 'a' in the above
example was set to "nox", the script would generate two beeps, but you would
hear only one. You can put a delay after the beep, or use some other form of
notification (like 'say...' or 'display dialog...')
Here's a script that checks the words as per your original intentions:
set myStringList to every word of "the fox oxon can count 1 2 3 and he love
nox"
set oxWords to {}
set oxNotFoxCount to 0
set noxCount to 0
repeat with theWord in myStringList
set theWord to theWord as string
if theWord contains "ox" then
if theWord is not "fox" then
set oxNotFoxCount to oxNotFoxCount + 1
end if
if theWord is "nox" then
set noxCount to noxCount + 1
end if
set end of oxWords to theWord
end if
end repeat
{oxWords, oxNotFoxCount, noxCount}
-->{{"fox", "oxon", "nox"}, 2, 1}
HTH
Nick
_______________________________________________
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.