 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ted Tripp Guest
|
Posted: Fri Apr 23, 2004 3:02 am Post subject: StringReplace |
|
|
Is there a faster StringReplace? My application is rather string intensive
manipulating strings averaging about 30-40k.
Thanks
Ted
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Apr 23, 2004 3:05 am Post subject: Re: StringReplace |
|
|
"Ted Tripp" <ttripp (AT) rankexec (DOT) com> wrote
| Quote: | Is there a faster StringReplace?
|
There is only 1 string replace.
| Quote: | My application is rather string intensive
manipulating strings averaging about 30-40k.
|
What kind of manipulation are you actually doing? Please show your actual
code. There is always ways to optimize string operations.
Gambit
|
|
| Back to top |
|
 |
Ted Tripp Guest
|
Posted: Fri Apr 23, 2004 7:52 pm Post subject: Re: StringReplace |
|
|
Well, I realize there is only one stringreplace. I guess my question has
more to do with is there a better algorithm that operates at a lower level.
StringReplace(asReallyBigString, "this", "that", TReplaceFlags() <<
rfReplaceAll);
I make many passes through several thousand large strings in order to parse
and make the text in each string "workable". I know there are a few ways I
can optimize this, but, in the end, memory is going to be shifted around a
few times with each string and CPU will take a hit.
So, the question is; is there a better optimized function than
StringReplace?
Thanks
Ted
"Remy Lebeau (TeamB)"
| Quote: |
"Ted Tripp" <ttripp (AT) rankexec (DOT) com> wrote in message
news:40888735 (AT) newsgroups (DOT) borland.com...
Is there a faster StringReplace?
There is only 1 string replace.
My application is rather string intensive
manipulating strings averaging about 30-40k.
What kind of manipulation are you actually doing? Please show your actual
code. There is always ways to optimize string operations.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Apr 23, 2004 9:52 pm Post subject: Re: StringReplace |
|
|
"Ted Tripp" <ttripp (AT) rankexec (DOT) com> wrote
| Quote: | StringReplace(asReallyBigString, "this", "that", TReplaceFlags()
rfReplaceAll);
|
In that specific example, since the source and target strings are the same
length, you could just loop through the raw string data and alter the
characters directly. No need to allocate a new string, ie:
char *ptr = AnsiStrPos(asReallyBigString.c_str(), "this");
while( ptr != NULL )
{
memcpy(ptr, "that", 4);
ptr = AnsiStrPos(ptr+4, "this");
}
If, in the off-chance that asReallyBigString is sharing the string data with
other AnsiString instances due to its reference-counted nature, then
allocate 1 new AnsiString and then make sure its reference count is unique
so that altering the characters won't effect other AnsiString instances, ie:
AnsiString Temp = asReallyBigString;
Temp.Unique();
char *ptr = AnsiStrPos(Temp.c_str(), "this");
//...
Or:
AnsiString Temp(asReallyBigString.c_str(), asReallyBigString.Length());
char *ptr = AnsiStrPos(Temp.c_str(), "this");
//...
| Quote: | I make many passes through several thousand large strings
in order to parse and make the text in each string "workable".
|
You might also try re-working your algorithm to reduce the number of passes
you need to make. If you need to make several passes, try to reduce the
range of characters they operate on rather than re-scanning the entire
string over and over.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Apr 23, 2004 9:53 pm Post subject: Re: StringReplace |
|
|
"Ted Tripp" <ttripp (AT) rankexec (DOT) com> wrote
| Quote: | So, the question is; is there a better optimized
function than StringReplace?
|
Again, as I stated originally, that depends on what you are ACTUALLY DOING
with the string in the first place.
Gambit
|
|
| Back to top |
|
 |
Fishface Guest
|
Posted: Fri Apr 23, 2004 11:15 pm Post subject: Re: StringReplace |
|
|
Ted Tripp wrote:
| Quote: | Is there a faster StringReplace? My application is rather
string intensive manipulating strings averaging about 30-40k.
|
Try this:
http://groups.google.com/groups?selm=mKxG7.12899%24Fr3.221223%40news1.oke.nextra.no
It's in Delphinese, but you can use it in BCB.
Stick it in a file called _StringReplace.pas
Add these lines to the file before the routine:
unit _StringReplace;
interface
function _StringReplace(const S, OldPattern, NewPattern: string;
implementation
{past here, but kill the brackets!}
Add it to your project, an .hpp will be created, add the .hpp to your
includes.
Alternately, you can try messing around with this:
www.mers.com/merlist/borland/public/cppbuilder/language/80867.html
I couldn't find it on Google, for some reason.
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Sat Apr 24, 2004 1:10 am Post subject: Re: StringReplace |
|
|
"Fishface" <invalid (AT) ddress (DOT) ok?> wrote
| Quote: | I couldn't find it on Google, for some reason.
|
There are no messages archived for that newsgroup during that time period.
Gambit
|
|
| Back to top |
|
 |
Ted Tripp Guest
|
Posted: Sat Apr 24, 2004 5:12 am Post subject: Re: StringReplace |
|
|
Thank you both. You gave me some things to work with.
TT
"Ted Tripp" <ttripp (AT) rankexec (DOT) com> wrote
| Quote: | Is there a faster StringReplace? My application is rather string
intensive
manipulating strings averaging about 30-40k.
Thanks
Ted
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|