Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

StringReplace - How replace all ocurrences?

Next code works fine one time but I don't know how (or where) must I include the parameter rfReplaceAll  to replace all occurrences.

procedure .....
var
 ..
 Flags: TReplaceFlags;
begin
 ..
 Memo1.Text := StringReplace(s, r1, r2, Flags);
 ..
end

Could anyone help me with the correct code?

Thanks.
0
boc7900
Asked:
boc7900
1 Solution
 
raidosCommented:
If you want to replace all occurances, you will have to use the rfReplaceAll flag yes..

Var
  Flags : TReplaceFlags;
Begin
  Flags := [rfReplaceAll];
  Memo1.Text := StringReplace(s, r1, r2, Flags);
End;

You might want to ignore the case of the oldpattern, in which case flags should be set like this :
  Flags := [rfReplaceAll, rfIgnoreCase];


//raidos
0
 
ITugayCommented:
Hi boc7900,

StringReplace(s, r1, r2, [rfReplaceAll]);
0
 
cubudCommented:
If you are working on a huge string, StringReplace (even in Delphi 6) is horrendously slow.  Use FastStrings !

http://www.stuckindoors.com/delphi/faststrings
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now