出于某种原因,使用
SearchText := 'Program Files';
ReplaceText := 'Program Files (x86)';
SearchAndReplace(SearchText, ReplaceText);
绝对不会做任何事情,只是不会改变文字,在使用任何其他文字时都能正常工作。
这是某种“储备”字吗?或者()是什么使它不起作用?
procedure Tfc_Great.SearchAndReplace
(InSearch, InReplace: string) ;
var X, ToEnd : integer;
oldCursor : TCursor;
begin
oldCursor := Screen.Cursor;
Screen.Cursor := crHourglass;
with RichEdit1 do
begin
X := 0;
ToEnd := length(Text) ;
X := FindText(inSearch, X, ToEnd, []) ;
while X <> -1 do
begin
SetFocus;
SelStart := X;
SelLength := length(inSearch) ;
SelText := InReplace;
X := FindText(inSearch,
X + length(InReplace),
ToEnd, []) ;
end;
end;
Screen.Cursor := oldCursor;
end;
答案 0 :(得分:1)
尝试分配输出;)
SearchText := 'Program Files';
ReplaceText := 'Program Files (x86)';
ResultText := SearchAndReplace(Text, SearchText, ReplaceText);
与
function SearchAndReplace
(sSrc, sLookFor, sReplaceWith : string) : string;
var
nPos, nLenLookFor : integer;
begin
nPos := Pos(sLookFor, sSrc) ;
nLenLookFor := Length(sLookFor) ;
while (nPos > 0) do begin
Delete(sSrc, nPos, nLenLookFor) ;
Insert(sReplaceWith, sSrc, nPos) ;
nPos := Pos(sLookFor, sSrc) ;
end;
Result := sSrc;
end;