Beranda > Delphi > Trimming all instances of a string from a string

Trimming all instances of a string from a string

This function is the same as TrimAllChar(), but removes all instances of a string from a string. Read the comment for the usage. Thanks to Jay ejp@ramss.com for this code.function TrimAllStr(const S: string; const Target : string): string;
{ func to remove instances of a string (Target) from a string (S). }
{ e.g. TrimAllStr(‘ABthis ABis ABa ABtest’, ‘AB’) will return ‘this is a test’. }
{ Thanks to Jay <ejp@ramss.com> for this code. }

var
P: integer;
begin
Result := S;
  repeat
P := Pos(Target, Result);
    if P > 0 then
System.Delete(Result, P, Length(Target));
  until
(P = 0);
end;

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: