Remove unwanted from string

procedure RemoveInvalid(what, where: string): string;

// what is the string to be removed, where is the string to be removed from

var

  tstr: string;

begin

  tstr:=where;

  while pos(what, tstr)>0 do

  tstr:=copy(tstr,1,pos(what,tstr)-1) +

  copy(tstr,pos(what,tstr)+length(tstr),length(tstr));

  Result:=tstr;

end;


Use:


 

  NewStr:=RemoveInvalid('<invalid>','This <invalid> is my string and I wan to

  remove the word <invalid>');


Use Pascal's DELETE...

using your example string, you could use code like....


Target:='<invalid>';

While POS(Target,string)>0 do

  begin

  P := POS(Target,string);

  DELETE(string,P,Length(Target));

  end;