请问怎样查找在一篇Word文档中指定的一个词一共出现了几次?
解决方案 »
- 咨询DELPHI日期时间格式转换问题
- AdoQuery 中的 AfterScroll 事件死循环问题求解!
- 变量赋值问题啊!!痛苦啊!
- !!!!高分求助: 如何重编译VCL组件库
- 关于dxdbgrid问题(在线等!)
- 编译运行时包RXCTL7.DPK时让我Run\Pamatemersm,之后出现一对话框,怎么编译
- 请问在程序中如何判断数据库中的主键字段是否存在?
- 删除.exe程序
- 高分请教:怎样让窗体内的控件随窗体的变化而变化
- 如何判断Edit中的内容是否为数字? 就好像Vb中的Isnumeric函数一样.
- 这个函数哪里错了,为什么在我的单元里不能使用????
- 密界高手多多指教!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
....procedure TMain.ReplaceBtnClick(Sender: TObject);
var
temp, SearchText, ReplaceText, All: OleVariant;
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, forward, wrap, format, replacewith, replace,
matchkashida, matchdiacritics, matchalefhamza, matchcontrol: olevariant;
TextRange: Range;
i: byte;
begin
TextRange := Doc.Content;
findtext := 'name';
replacewith := '张三';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
forward := true;
wrap := wdFindContinue;
format := false;
Replace := true;
i := 0;
while TextRange.find.execute(findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms,
forward, wrap, format, replacewith, replace, matchkashida,
matchdiacritics, matchalefhamza, matchcontrol)
do begin
inc(i);
end;
end;
....procedure TMain.ReplaceBtnClick(Sender: TObject);
var
temp, SearchText, ReplaceText, All: OleVariant;
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, forward, wrap, format, replacewith, replace,
matchkashida, matchdiacritics, matchalefhamza, matchcontrol: olevariant;
i: byte;
begin
//====================================
findtext := '我';
replacewith := '??????';
//====================================
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
forward := true;
wrap := wdFindContinue;
format := false;
Replace := true;
i := 0;
while Doc.ActiveWindow.Selection.find.execute(findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms,
forward, wrap, format, replacewith, replace, matchkashida,
matchdiacritics, matchalefhamza, matchcontrol)
do begin
inc(i);
end;//===============以下这部分是我加的================
findtext := '??????';
replacewith := '我';
while Doc.ActiveWindow.Selection.find.execute(findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms,
forward, wrap, format, replacewith, replace, matchkashida,
matchdiacritics, matchalefhamza, matchcontrol)
do begin
inc(i);
end;
//=======================================================
end;理论上讲,当第一个while执行完后,文章中的“我”全部被替换成“??????”;此后,执行第二个while,又将所有的“??????”,还原成“我”。但实际实行的结果是,当执行到第二个while的时候,始终无法跳出循环,并且,所有的“??????”都没有被还原成“我”。请问我错在哪里?
aCount:integer;
....procedure TMain.ReplaceBtnClick(Sender: TObject);
var
temp, SearchText, ReplaceText, All: OleVariant;
findtext, matchcase, matchwholeword, matchwildcards, matchsoundslike,
matchallwordforms, forward, wrap, format, replacewith, replace,
matchkashida, matchdiacritics, matchalefhamza, matchcontrol: olevariant;
TextRange: Range;
i: byte;
begin
TextRange := Doc.Content;
findtext := 'name';
replacewith := '张三';
matchcase := false;
matchwholeword := true;
matchwildcards := false;
matchsoundslike := false;
matchallwordforms := false;
forward := true;
wrap := wdFindContinue;
format := false;
Replace := true;
i := 0;
while TextRange.find.execute(findtext, matchcase, matchwholeword,
matchwildcards, matchsoundslike, matchallwordforms,
forward, wrap, format, replacewith, replace, matchkashida,
matchdiacritics, matchalefhamza, matchcontrol)
do begin
inc(i);
end;
aCount:=i;//这个就是获得出现次数
Showmessage(IntToStr(aCount));
end;
”。这确实没错。但上面的程序执行完后,文章中所有的'name',应经被替换成'张三'。我想把 '张三' 再替换回'name',于是我在后面又加了一段(内容见3楼),这导致了错误。我不明白错在哪里,请指点!