procedure TForm1.Button1Click(Sender: TObject);
var
b,c: integer; //循环用
begin
for c:=0 to Memo3.Lines.Count-1 do//循环得到memo3中的一行
begin
  for b:=0 to Memo2.Lines.Count-1 do//循环得到memo2中的一行
  begin
    memo1.Text:= stringreplace(memo1.Text,Memo2.Lines.Strings[b],Memo3.Lines.Strings[c],[rfreplaceall]);//用memo2中的一行来搜索memo1中相同的文字,用memo3中的一行代替该段文字
  end;
end;
end;
这样memo1中的全部行会被替换成memo3的第一行真心求各位大神解答

解决方案 »

  1.   

    不要循环,直接一次:memo1.Text:= stringreplace(memo1.Text,Memo2.Lines.Strings[  3  ],Memo3.Lines.Strings[  1  ],[rfreplaceall]);
      

  2.   

    我的意思是3个memo都有几十行文字,想要用循环,用memo2的第一行搜索memo1里全部相同的文字,用memo3的第一行来替换memo1里那些相同的文字
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
    b,c: integer; //循环用
    begin
    for c:=0 to Memo3.Lines.Count-1 do//循环得到memo3中的一行
    begin
      for b:=0 to Memo2.Lines.Count-1 do//循环得到memo2中的一行
      begin
        memo1.Text:= stringreplace(memo1.Text,Memo2.Lines.Strings[b],Memo3.Lines.Strings[c],[rfreplaceall]);//用memo2中的一行来搜索memo1中相同的文字,用memo3中的一行代替该段文字
      end;
    end;
    end;不要偷懒啦,还是copy+pos函数吧
    iIndex:=pos(memo2.Lines[c],memo1.Lines[b]);
    if  iIndex>0 then
       memo1.Text:= copy(memo1.text,0,iIndex-1)+
                                  memo3.Lines[a]+
                                  copy(memo1.Lines[c],iIndex-1+(length(memo2.Lines[b]),length(memo1.Lines[c]));
      

  4.   

    TMemo的lines就是tstrings for c:=0 to Memo3.Lines.Count-1 do//循环得到memo3中的一行
      for b:=0 to Memo2.Lines.Count-1 do//循环得到memo2中的一行
        memo1.Text:= stringreplace(memo1.Text,Memo2.Lines[b],Memo3.Lines[c],[rfreplaceall]);//用memo2中的
      

  5.   

    我的理解不知道对不对,Memo1、Memo2、Memo3都是同样行数的内容,3个Memo分别一行一行的进行替换操作,替换的内容是Memo1为原文,Memo2为匹配文件,Memo3为替换文件是吗??