Learn how to a build a cloud-first strategyRegister Now

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

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!
0
AngeloX
Asked:
AngeloX
1 Solution
 
rbohacCommented:
One way to do it is

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

0
 
paulb1989Commented:
You can do the same as above but much faster using FastReplace from http://www.droopyeyes.com/default.asp?mode=ShowProduct&ID=4
0
 
DragonSlayerCommented:
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AngeloXAuthor Commented:
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!
0
 
mokuleCommented:
Hi,
Maybe You can find it usefull for stringreplace
http://dennishomepage.gugs-cats.dk/AnsiStrReplaceChallenge.htm
0
 
AngeloXAuthor Commented:
That one was fast enough hehe. Thnx!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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