Re: Count of specific string in Word (was re: Count of Tab characters)
Re: Count of specific string in Word (was re: Count of Tab characters)
- Subject: Re: Count of specific string in Word (was re: Count of Tab characters)
- From: Jed Verity <email@hidden>
- Date: Mon, 12 Feb 2001 21:18:52 -0800
Hi Bill,
This should delete any paragraph with zwx in it (though I haven't tried it
with exceptionally large documents):
---begin script
property badString : "zwx" --this is the string to look for
tell application "Microsoft Word"
set docBody to (get paragraphs of text of document 1) --working with
first open document
set newBody to my RidBadPars(docBody)
set text of document 1 to newBody
end tell
to RidBadPars(docBody)
set newDocBod to {}
set parCount to count items of docBody
repeat with i from 1 to parCount
if not (item i of docBody contains badString) then
set end of newDocBod to item i of docBody
end if
end repeat
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set newDocBod to newDocBod as text
set AppleScript's text item delimiters to oldDelims
newDocBod
end RidBadPars
---end script
HTH,
Jed
On 2/12/01 8:20 PM, Bill Planey uttered these immortal words:
>
I desperately need a way to count the number of occurrences of a
>
specified string in MS Word. I have a script which puts a placeholder
>
in certain paragraphs that have met my criteria. This placeholder is
>
"zwx".
>
>
I want the script to either:
>
>
delete any paragraph which is found to contain the string by
>
using a broad statement to do so, something like:
>
>
tell MS Word
>
for any paragraph which contains string "zwx"
>
delete entire paragraph
>
end tell
>
>
or:
>
>
tell MS Word
>
set count of paragraphs which contain string "zwx" to ParaCount
>
repeat ParaCount times
>
find string "zwx"
>
extend selection to entire paragraph
>
delete selection
>
end repeat
>
end tell
>
>
Now, I know my "code" above is wrong, I just wanted to simply express
>
the concept. Anyone out there with some experience with this kind of
>
thing?
>
>
Thanks!!!
>
>
Bill Planey
>
_______________________________________________
>
applescript-users mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/applescript-users
>
~)~)~)~)~)~)~)~)~)~)~)~)~)
Jed Verity