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;
上面的函数将所有包括Substr的字符都删除
自己写一个函数: 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;
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;
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;
edit2.text:=stringreplace(edit1.text,'"','',rfReplaceAll);[Error] Unit1.pas(30): Incompatible types: 'TReplaceFlags' and 'Enumeration'