我正在尝试计算 MS Word 文档中特殊字符串的出现总数。搜索字符串是:(\{F)(*)(\})
。
function CountOcc(SString:string): Integer;
var
aFindText, aMatchCase,aWrap,AMatchWholeWord,aReplaceWith,aReplace: OleVariant;
Result1: boolean
begin
Result := False;
aFindText := SString;
aMatchCase := false;
aMatchWholeWord := true;
aWrap := wdFindContinue;
aReplace:=wdReplaceNone;
aMatchWildCards:=true;
aReplaceWith:=SString;
try
Result1:=WordContainer.OleObject.ActiveWindow.Selection.Range.Find.Execute(
aFindText
, aMatchCase
, aMatchWholeWord
, aMatchWildCards
, EmptyParam, EmptyParam, EmptyParam, aWrap, EmptyParam
, aReplaceWith, aReplace
, EmptyParam, EmptyParam,EmptyParam, EmptyParam);
finally
if Result1 then ........
end;
end;
如何获取搜索字符串的出现次数?