0

我有这样的文件:

English English English English

中文中文中文中文中文

English English English English

中文中文中文中文

英文段落和中文段落依次显示。

那么,有没有办法让我删除所有英文段落?

我知道grep并且我知道如何使用regex以及诸如awk sed.. 但我想在 Microsoft Word 中进行操作,所以:

如何通过 AppleScript 解决这个问题?

多谢你们!

4

1 回答 1

1

这不是很漂亮,但它应该可以完成工作。

property english : "abcdefghijklmnopqrstuvwxyz"
set deleteMe to {}

tell application "Microsoft Word"
    tell active document
        set pCount to count of paragraphs
        repeat with i from 1 to pCount
            set cCount to count of characters in characters of paragraph i
            repeat with j from 1 to cCount
                tell paragraph i
                    if content of character j is in english then
                        set end of deleteMe to i
                        exit repeat
                    end if
                end tell
            end repeat
        end repeat

        set dCount to -(count of deleteMe)
        repeat with k from -1 to dCount by -1
            set content of text object of paragraph (item k of deleteMe) to "" -- delete paragraph
        end repeat
    end tell
end tell
于 2012-06-20T12:36:15.693 回答