请问怎样删除字符串中的指定的子串?

解决方案 »

  1.   

    function dele_Str(substr, Str :string) :string ;
    begin
      if Pos(substr,Str) < 1 then
      begin
        Result := Str ;
      end
      else
      begin
         Result :=Result + dele_Str(substr, Copy(Str,1,Pos(substr,Str)-1)
                  +Copy(Str,Pos(substr,Str)+length(substr),Length(Str)-(Pos(substr,Str)+length(substr))) );
      end  ;
    end ;
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
     Label1.Caption :=dele_Str('123','1235888558123');
    end;
      

  2.   

    上面的函数将所有包括Substr的字符都删除
      

  3.   

    自己写一个函数:
    function deletestr(str1:string;str2:string):string;
    var
      p,l1,l2:integer;
      str:string;
    begin
      result:=str1;
      l1:=length(str1);
      l2:=length(str2);
      p:=pos(str2,str1);
      if p>0 then
      result:=copy(str1,1,p-1)+copy(str1,p+l2,l1-p-l2+1);
    end;
      

  4.   

    StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;用''代替你要删除的就OK了,试一试!
      

  5.   

    我这样写为什么报错啊
    edit2.text:=stringreplace(edit1.text,'"','',rfReplaceAll);[Error] Unit1.pas(30): Incompatible types: 'TReplaceFlags' and 'Enumeration'