Elie Boulos wrote:
I need to find the number of instances of an arbitrary string
in a single text file, is this possible through AppleScript?
Search matches doesn't have such a number.
For example, I need to find out the count of the word 'and' in
a text containing "He bought a hammer and a nail and a tape and
a screw driver" (that's 3 and's)
Possible?
I'd use the replace command and replace "and" by "and". The result will
be the number of occurrences replaced:
set theWord to "and"
set a to replace theWord using theWord searching in contents of document
1 options {starting at top:true}
display dialog a
But I am sure there are other ways to skin this cat. Using this method
you either have to pay attention to your case sensitivity option so that
the text is not changed into something you do not want, or take care not
to save the document after the search.
--
---
Kjetil Rå Hauge, U. of Oslo, PO Box 1003 Blindern, N-0315 Oslo, Norway
Tel. +47/22856710, fax +47/22854140
--
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>