Algorithm Math Delphi

Title: How to realize a filtered substring search
function filterSubStr(tmp, von, bis: string; a: Integer): string;
var
SubStr, bck: string;
Pos1, Pos2, i: Integer;
begin
i := 0;
while i do
begin
Pos1 := Pos(von, tmp);
Pos2 := Pos(bis, tmp);
SubStr := Copy(tmp, Pos1 + Length(von), Pos2 - Pos1 - Length(von));
Delete(tmp, Pos1, Pos2 - Pos1 + Length(bis));
if SubStr = '' then {nothing}
else if bck = '' then
bck := SubStr
else
bck := bck + #13#10 + SubStr;
i := i + 1;
end;
Result := bck;
end;