Link to home
Start Free TrialLog in
Avatar of AngeloX
AngeloX

asked on

I need the fastest find and replace ever made.

I need the fastest find and replace ever made. Maybe not really the fastest, but i just want to find and replace the right way.
For example string is a text of length of 30. i have a list of words that I want to find in the string and replace them with 'xyz'.

Do you have any idea what the best way is to load the list of words and then do the replacing?

Thnx!
Avatar of rbohac
rbohac

One way to do it is

  Str := StringReplace(Str,Key,'xyz',[rfReplaceAll]);

ASKER CERTIFIED SOLUTION
Avatar of paulb1989
paulb1989

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or get madshi's components, and do a

uses
  madString;

// assuming that your keyword list is already in a TStringList called Keywords

for i := 0 to Keywords.Count - 1 do
  ReplaceStr(Str, Keywords[i], 'xyz', True);


from Madshi's help file:

The following functions search through the whole "str" and replace the fragment "replaceThis" every time it occurs "withThis". The replacement can be done recursively, if you wish. That means, that the replaced string fragments are checked again. "ReplaceStr" searches case sensitively, while "ReplaceText" searches case insensitively.

function ReplaceStr  (var str     : string;
                      replaceThis : string;
                      withThis    : string;
                      replaceSelf : boolean = false) : boolean;
function ReplaceText (var str     : string;
                      replaceThis : string;
                      withThis    : string;
                      replaceSelf : boolean = false) : boolean;

Get his package from www.madshi.net
Avatar of AngeloX

ASKER

Thnx I guess FastStrings will do. But do you also have any idea what the best way is to load a list of words and then go by them one for one? Is the fastest way to load them in a TList and then do a for loop for every word, or is there a faster way to do that?

Thnx!
Hi,
Maybe You can find it usefull for stringreplace
http://dennishomepage.gugs-cats.dk/AnsiStrReplaceChallenge.htm
Avatar of AngeloX

ASKER

That one was fast enough hehe. Thnx!