• 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: Newbie, every word where it contains "ox"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Newbie, every word where it contains "ox"
      • From: Paul Berkowitz <email@hidden>
References: 
 >Newbie, every word where it contains "ox" (From: Steen <email@hidden>)

  • Prev by Date: Re: selective string-replace
  • Next by Date: Re: Photoshop 7 (OS X)
  • Previous by thread: Re: Newbie, every word where it contains "ox"
  • Next by thread: Re: Newbie, every word where it contains "ox"
  • Index(es):
    • Date
    • Thread