473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

String.Replace( ) vs. StringBuilder.Replace( )

Hi,

I know this has been asked before, but reading the threads it is still not
entirely clear.
Deciding which .Replace( ) to use when.

Typically if I create a string in a loop I always use a StringBuilder. At
present I am
porting a VB6 webclass app to VB.NET and therefore I am trying to make it as
efficent as possible via the new functionality of VB.NET.

At present I have (in various places):
variableX = variableX.Replace("a string", "another string")

In some cases the above variableX will have 4+ replaces virutally one after
the
other with 1 or 2 of the replacement strings having length > 100.

This seems like the perfect candidate for StringBuilder.Replace instead of
String.Replace
what does anybody think?

Regards,
Pete
Nov 20 '05 #1
9 9105
Hi,

When you use variableX = variableX.Replace("a string", "another
string") with a string it will it will create a new string in memory and
destroy the old one. The stringbuilder will reuse the memory space
therefore it is quicker.

http://msdn.microsoft.com/library/de...ilderclass.asp

Ken
----------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hi,

I know this has been asked before, but reading the threads it is still not
entirely clear.
Deciding which .Replace( ) to use when.

Typically if I create a string in a loop I always use a StringBuilder. At
present I am
porting a VB6 webclass app to VB.NET and therefore I am trying to make it
as
efficent as possible via the new functionality of VB.NET.

At present I have (in various places):
variableX = variableX.Replace("a string", "another string")

In some cases the above variableX will have 4+ replaces virutally one
after
the
other with 1 or 2 of the replacement strings having length > 100.

This seems like the perfect candidate for StringBuilder.Replace instead of
String.Replace
what does anybody think?

Regards,
Pete

Nov 20 '05 #2
Hi,

The link provided gives a lot of info but leaves out some important info
hence the original question.

If I have a stringbuilder and lets say it has length = 100, I also have
strHeaderStuff with length = 200.
For the sake of argument lets also say that .IndexOf("<head>") is 25 and I
say:

MyStrBldr.Replace("<head>", strHeaderStuff)

The stringbuilder object is increasing it's size and inserting at a position
it has to find first.
So I still need to be convinced that doing it this way will be faster than
doing:

SimpleString = SimpleString.Replace("<head>", strHeaderStuff)

I don't wanna start a massive flaming debate about the rights and wrongs of
anything but...
wouldn't it of made more sense for MS to implement the String type to do the
same as a
StringBuilder under the covers and hence not have StringBuilder?

i.e
Dim str As String
Str = "Hello"
Str &= " World"

Is roughly the same as saying:
Dim sbr As New StringBuilder
sbr.Append("Hello")
sbr.Append(" World")

So if the stringbuilder is so much more efficent why not simply implement
the String that way
in the first place?

Regards,
Peter

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OA**************@TK2MSFTNGP12.phx.gbl...
Hi,

When you use variableX = variableX.Replace("a string", "another
string") with a string it will it will create a new string in memory and
destroy the old one. The stringbuilder will reuse the memory space
therefore it is quicker.

http://msdn.microsoft.com/library/de...ilderclass.asp
Ken
----------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hi,

I know this has been asked before, but reading the threads it is still not entirely clear.
Deciding which .Replace( ) to use when.

Typically if I create a string in a loop I always use a StringBuilder. At present I am
porting a VB6 webclass app to VB.NET and therefore I am trying to make it as
efficent as possible via the new functionality of VB.NET.

At present I have (in various places):
variableX = variableX.Replace("a string", "another string")

In some cases the above variableX will have 4+ replaces virutally one
after
the
other with 1 or 2 of the replacement strings having length > 100.

This seems like the perfect candidate for StringBuilder.Replace instead of String.Replace
what does anybody think?

Regards,
Pete


Nov 20 '05 #3
Cor
Hi Peter,

Only an answer on your question,

I asume that making a string as dim mystring as String = "Peter" with the
stringbuilder is a little bit overdone.

But nobody is keeping you from doing it with stringbuilder, that is what I
find so nice from VB.net, you can make your own decissions how you do it.

When that is gone you can take a tool as Access.

But just my thought,
Cor
Nov 20 '05 #4
Hi,

The stringbuilder will only resize if the string is larger.

Ken
---------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
Hi,

The link provided gives a lot of info but leaves out some important info
hence the original question.

If I have a stringbuilder and lets say it has length = 100, I also have
strHeaderStuff with length = 200.
For the sake of argument lets also say that .IndexOf("<head>") is 25 and I
say:

MyStrBldr.Replace("<head>", strHeaderStuff)

The stringbuilder object is increasing it's size and inserting at a
position
it has to find first.
So I still need to be convinced that doing it this way will be faster than
doing:

SimpleString = SimpleString.Replace("<head>", strHeaderStuff)

I don't wanna start a massive flaming debate about the rights and wrongs
of
anything but...
wouldn't it of made more sense for MS to implement the String type to do
the
same as a
StringBuilder under the covers and hence not have StringBuilder?

i.e
Dim str As String
Str = "Hello"
Str &= " World"

Is roughly the same as saying:
Dim sbr As New StringBuilder
sbr.Append("Hello")
sbr.Append(" World")

So if the stringbuilder is so much more efficent why not simply implement
the String that way
in the first place?

Regards,
Peter

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OA**************@TK2MSFTNGP12.phx.gbl...
Hi,

When you use variableX = variableX.Replace("a string", "another
string") with a string it will it will create a new string in memory and
destroy the old one. The stringbuilder will reuse the memory space
therefore it is quicker.

http://msdn.microsoft.com/library/de...ilderclass.asp

Ken
----------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I know this has been asked before, but reading the threads it is still not > entirely clear.
> Deciding which .Replace( ) to use when.
>
> Typically if I create a string in a loop I always use a StringBuilder. At > present I am
> porting a VB6 webclass app to VB.NET and therefore I am trying to make it > as
> efficent as possible via the new functionality of VB.NET.
>
> At present I have (in various places):
> variableX = variableX.Replace("a string", "another string")
>
> In some cases the above variableX will have 4+ replaces virutally one
> after
> the
> other with 1 or 2 of the replacement strings having length > 100.
>
> This seems like the perfect candidate for StringBuilder.Replace instead of > String.Replace
> what does anybody think?
>
> Regards,
> Pete
>
>



Nov 20 '05 #5
Hi,

Eh? I don't get what you are saying?

If I have a SBuilder with length 100 and I replace "<head>" (length 6) with
a string
that is 200 in length then the Sbuilder has no choice but to resize surely;
because
you are replacing 6 out of 100 with 200 hence the length after the replace
would be
294 which is 194 larger than before the operation??

Therefore since it is resizing it then you'd assume there is some overhead
to that.
So how does that overhead compare to doing a :
Str = Str.Replace("<head>", str2)

Regards,
Peter
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

The stringbuilder will only resize if the string is larger.

Ken
---------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
Hi,

The link provided gives a lot of info but leaves out some important info
hence the original question.

If I have a stringbuilder and lets say it has length = 100, I also have
strHeaderStuff with length = 200.
For the sake of argument lets also say that .IndexOf("<head>") is 25 and I
say:

MyStrBldr.Replace("<head>", strHeaderStuff)

The stringbuilder object is increasing it's size and inserting at a
position
it has to find first.
So I still need to be convinced that doing it this way will be faster than doing:

SimpleString = SimpleString.Replace("<head>", strHeaderStuff)

I don't wanna start a massive flaming debate about the rights and wrongs
of
anything but...
wouldn't it of made more sense for MS to implement the String type to do
the
same as a
StringBuilder under the covers and hence not have StringBuilder?

i.e
Dim str As String
Str = "Hello"
Str &= " World"

Is roughly the same as saying:
Dim sbr As New StringBuilder
sbr.Append("Hello")
sbr.Append(" World")

So if the stringbuilder is so much more efficent why not simply implement the String that way
in the first place?

Regards,
Peter

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OA**************@TK2MSFTNGP12.phx.gbl...
Hi,

When you use variableX = variableX.Replace("a string", "another
string") with a string it will it will create a new string in memory and destroy the old one. The stringbuilder will reuse the memory space
therefore it is quicker.

http://msdn.microsoft.com/library/de...ilderclass.asp

Ken
----------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I know this has been asked before, but reading the threads it is

still not
> entirely clear.
> Deciding which .Replace( ) to use when.
>
> Typically if I create a string in a loop I always use a
StringBuilder. At
> present I am
> porting a VB6 webclass app to VB.NET and therefore I am trying to
make it
> as
> efficent as possible via the new functionality of VB.NET.
>
> At present I have (in various places):
> variableX = variableX.Replace("a string", "another string")
>
> In some cases the above variableX will have 4+ replaces virutally one
> after
> the
> other with 1 or 2 of the replacement strings having length > 100.
>
> This seems like the perfect candidate for StringBuilder.Replace
instead of
> String.Replace
> what does anybody think?
>
> Regards,
> Pete
>
>



Nov 20 '05 #6
Hi,

The point I was making was that since when dealing with Strings that are
appended
and replaced over and over the stringbuilder is more efficent then why
bother
making the distinction.

All it does is give you a pointless decision which in some cases is very
close.
It boils down to this:
Do you want your app to run fast/efficently or run okay/more-or-less
efficent?

Well I would always choose fast/efficently as I'm sure most people would,
therefore
why complicate the issue by having String and StringBuilder? Why not just
have
String which works like StringBuilder under the covers?

Finally don't be so digusting!!! Mentioning MS Access, urrgghh!

Regards,
Peter
"Cor" <no*@non.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi Peter,

Only an answer on your question,

I asume that making a string as dim mystring as String = "Peter" with the
stringbuilder is a little bit overdone.

But nobody is keeping you from doing it with stringbuilder, that is what I
find so nice from VB.net, you can make your own decissions how you do it.

When that is gone you can take a tool as Access.

But just my thought,
Cor

Nov 20 '05 #7
Hi,

I guess in that case there would be no real improvement.

Ken
-----------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:es**************@tk2msftngp13.phx.gbl...
Hi,

Eh? I don't get what you are saying?

If I have a SBuilder with length 100 and I replace "<head>" (length 6)
with
a string
that is 200 in length then the Sbuilder has no choice but to resize
surely;
because
you are replacing 6 out of 100 with 200 hence the length after the replace
would be
294 which is 194 larger than before the operation??

Therefore since it is resizing it then you'd assume there is some overhead
to that.
So how does that overhead compare to doing a :
Str = Str.Replace("<head>", str2)

Regards,
Peter
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

The stringbuilder will only resize if the string is larger.

Ken
---------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> The link provided gives a lot of info but leaves out some important
> info
> hence the original question.
>
> If I have a stringbuilder and lets say it has length = 100, I also have
> strHeaderStuff with length = 200.
> For the sake of argument lets also say that .IndexOf("<head>") is 25
> and I > say:
>
> MyStrBldr.Replace("<head>", strHeaderStuff)
>
> The stringbuilder object is increasing it's size and inserting at a
> position
> it has to find first.
> So I still need to be convinced that doing it this way will be faster than > doing:
>
> SimpleString = SimpleString.Replace("<head>", strHeaderStuff)
>
> I don't wanna start a massive flaming debate about the rights and
> wrongs
> of
> anything but...
> wouldn't it of made more sense for MS to implement the String type to
> do
> the
> same as a
> StringBuilder under the covers and hence not have StringBuilder?
>
> i.e
> Dim str As String
> Str = "Hello"
> Str &= " World"
>
> Is roughly the same as saying:
> Dim sbr As New StringBuilder
> sbr.Append("Hello")
> sbr.Append(" World")
>
> So if the stringbuilder is so much more efficent why not simply implement > the String that way
> in the first place?
>
> Regards,
> Peter
>
> "Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
> news:OA**************@TK2MSFTNGP12.phx.gbl...
>> Hi,
>>
>> When you use variableX = variableX.Replace("a string",
>> "another
>> string") with a string it will it will create a new string in memory and >> destroy the old one. The stringbuilder will reuse the memory space
>> therefore it is quicker.
>>
>>
> http://msdn.microsoft.com/library/de...ilderclass.asp >>
>> Ken
>> ----------------------
>> "Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
>> news:eV**************@TK2MSFTNGP09.phx.gbl...
>> > Hi,
>> >
>> > I know this has been asked before, but reading the threads it is still > not
>> > entirely clear.
>> > Deciding which .Replace( ) to use when.
>> >
>> > Typically if I create a string in a loop I always use a StringBuilder. > At
>> > present I am
>> > porting a VB6 webclass app to VB.NET and therefore I am trying to make > it
>> > as
>> > efficent as possible via the new functionality of VB.NET.
>> >
>> > At present I have (in various places):
>> > variableX = variableX.Replace("a string", "another string")
>> >
>> > In some cases the above variableX will have 4+ replaces virutally
>> > one
>> > after
>> > the
>> > other with 1 or 2 of the replacement strings having length > 100.
>> >
>> > This seems like the perfect candidate for StringBuilder.Replace instead > of
>> > String.Replace
>> > what does anybody think?
>> >
>> > Regards,
>> > Pete
>> >
>> >
>>
>>
>
>



Nov 20 '05 #8
Peter,
Remember that the StringBuilder over allocates its buffer, a string only
ever holds how ever many characters are in it!

The StringBuilder.Capacity property is how many characters the buffer will
hold, while StringBuilder.Length is how many characters are in use. Normally
you should set StringBuilder.Capacity to a value larger then the expected
resultant string. Other wise as Ken stated the StringBuilder will need to
reallocate its buffer. When the StringBuilder reallocates its buffer, it
doubles it in size, which means after a couple reallocates it is probably
significantly larger then it needs to be, by default capacity starts at 16.
By setting the Capacity value when you start (in the constructor for
example) you save the reallocations of the StringBuilder's buffer. You can
use StringBuilder.MaxCapacity to limit to maximum capacity that a
StringBuilder can be expanded to.

For example, I am creating a new StringBuilder that is initialized to my
template "<head><body><tail>", however I am setting the capacity of that
StringBuilder to 1024, which is clearly larger then my three replacement
values. When I use sb.Replace, because the buffer capacity is larger then
the result, the buffer is not reallocated...

Dim sb As New StringBuilder("<head><body><tail>", 1024)
Dim head As New String("h"c, 200)
Dim body As New String("b"c, 200)
Dim tail As New String("t"c, 200)

sb.Replace("<head>", head)
sb.Replace("<body>", body)
sb.Replace("<tail>", tail)

Hope this helps
Jay

"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:es**************@tk2msftngp13.phx.gbl...
Hi,

Eh? I don't get what you are saying?

If I have a SBuilder with length 100 and I replace "<head>" (length 6) with a string
that is 200 in length then the Sbuilder has no choice but to resize surely; because
you are replacing 6 out of 100 with 200 hence the length after the replace
would be
294 which is 194 larger than before the operation??

Therefore since it is resizing it then you'd assume there is some overhead
to that.
So how does that overhead compare to doing a :
Str = Str.Replace("<head>", str2)

Regards,
Peter
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

The stringbuilder will only resize if the string is larger.

Ken
---------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
Hi,

The link provided gives a lot of info but leaves out some important info hence the original question.

If I have a stringbuilder and lets say it has length = 100, I also have strHeaderStuff with length = 200.
For the sake of argument lets also say that .IndexOf("<head>") is 25 and
I
say:

MyStrBldr.Replace("<head>", strHeaderStuff)

The stringbuilder object is increasing it's size and inserting at a
position
it has to find first.
So I still need to be convinced that doing it this way will be faster than doing:

SimpleString = SimpleString.Replace("<head>", strHeaderStuff)

I don't wanna start a massive flaming debate about the rights and
wrongs of
anything but...
wouldn't it of made more sense for MS to implement the String type to do the
same as a
StringBuilder under the covers and hence not have StringBuilder?

i.e
Dim str As String
Str = "Hello"
Str &= " World"

Is roughly the same as saying:
Dim sbr As New StringBuilder
sbr.Append("Hello")
sbr.Append(" World")

So if the stringbuilder is so much more efficent why not simply

implement the String that way
in the first place?

Regards,
Peter

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OA**************@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> When you use variableX = variableX.Replace("a string", "another> string") with a string it will it will create a new string in memory and> destroy the old one. The stringbuilder will reuse the memory space
> therefore it is quicker.
>
>

http://msdn.microsoft.com/library/de...ilderclass.asp
>
> Ken
> ----------------------
> "Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
> news:eV**************@TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> > I know this has been asked before, but reading the threads it is still not
> > entirely clear.
> > Deciding which .Replace( ) to use when.
> >
> > Typically if I create a string in a loop I always use a StringBuilder. At
> > present I am
> > porting a VB6 webclass app to VB.NET and therefore I am trying to make it
> > as
> > efficent as possible via the new functionality of VB.NET.
> >
> > At present I have (in various places):
> > variableX = variableX.Replace("a string", "another string")
> >
> > In some cases the above variableX will have 4+ replaces virutally one> > after
> > the
> > other with 1 or 2 of the replacement strings having length > 100.
> >
> > This seems like the perfect candidate for StringBuilder.Replace instead of
> > String.Replace
> > what does anybody think?
> >
> > Regards,
> > Pete
> >
> >
>
>



Nov 20 '05 #9
Hi,

At last someone that has something worthwhile to say, thanks!

So basically you have to take an educated guess based on your situation and
set the capacity.
I will have to do that as a phase 2 optimisation on my porting from VB6
project as I haven't
been setting the capacity when I use one.

Regards,
Peter
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:ue**************@TK2MSFTNGP10.phx.gbl...
Peter,
Remember that the StringBuilder over allocates its buffer, a string only
ever holds how ever many characters are in it!

The StringBuilder.Capacity property is how many characters the buffer will
hold, while StringBuilder.Length is how many characters are in use. Normally you should set StringBuilder.Capacity to a value larger then the expected
resultant string. Other wise as Ken stated the StringBuilder will need to
reallocate its buffer. When the StringBuilder reallocates its buffer, it
doubles it in size, which means after a couple reallocates it is probably
significantly larger then it needs to be, by default capacity starts at 16. By setting the Capacity value when you start (in the constructor for
example) you save the reallocations of the StringBuilder's buffer. You can use StringBuilder.MaxCapacity to limit to maximum capacity that a
StringBuilder can be expanded to.

For example, I am creating a new StringBuilder that is initialized to my
template "<head><body><tail>", however I am setting the capacity of that
StringBuilder to 1024, which is clearly larger then my three replacement
values. When I use sb.Replace, because the buffer capacity is larger then
the result, the buffer is not reallocated...

Dim sb As New StringBuilder("<head><body><tail>", 1024)
Dim head As New String("h"c, 200)
Dim body As New String("b"c, 200)
Dim tail As New String("t"c, 200)

sb.Replace("<head>", head)
sb.Replace("<body>", body)
sb.Replace("<tail>", tail)

Hope this helps
Jay

"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:es**************@tk2msftngp13.phx.gbl...
Hi,

Eh? I don't get what you are saying?

If I have a SBuilder with length 100 and I replace "<head>" (length 6) with
a string
that is 200 in length then the Sbuilder has no choice but to resize

surely;
because
you are replacing 6 out of 100 with 200 hence the length after the replace
would be
294 which is 194 larger than before the operation??

Therefore since it is resizing it then you'd assume there is some overhead to that.
So how does that overhead compare to doing a :
Str = Str.Replace("<head>", str2)

Regards,
Peter
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

The stringbuilder will only resize if the string is larger.

Ken
---------------------
"Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
news:Ow**************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> The link provided gives a lot of info but leaves out some important info > hence the original question.
>
> If I have a stringbuilder and lets say it has length = 100, I also have > strHeaderStuff with length = 200.
> For the sake of argument lets also say that .IndexOf("<head>") is 25 and
I
> say:
>
> MyStrBldr.Replace("<head>", strHeaderStuff)
>
> The stringbuilder object is increasing it's size and inserting at a
> position
> it has to find first.
> So I still need to be convinced that doing it this way will be faster than
> doing:
>
> SimpleString = SimpleString.Replace("<head>", strHeaderStuff)
>
> I don't wanna start a massive flaming debate about the rights and wrongs > of
> anything but...
> wouldn't it of made more sense for MS to implement the String type
to do > the
> same as a
> StringBuilder under the covers and hence not have StringBuilder?
>
> i.e
> Dim str As String
> Str = "Hello"
> Str &= " World"
>
> Is roughly the same as saying:
> Dim sbr As New StringBuilder
> sbr.Append("Hello")
> sbr.Append(" World")
>
> So if the stringbuilder is so much more efficent why not simply

implement
> the String that way
> in the first place?
>
> Regards,
> Peter
>
> "Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
> news:OA**************@TK2MSFTNGP12.phx.gbl...
>> Hi,
>>
>> When you use variableX = variableX.Replace("a string", "another >> string") with a string it will it will create a new string in
memory and
>> destroy the old one. The stringbuilder will reuse the memory space
>> therefore it is quicker.
>>
>>
>

http://msdn.microsoft.com/library/de...ilderclass.asp >>
>> Ken
>> ----------------------
>> "Peter Row" <pe*******@oxfordcc.co.uk> wrote in message
>> news:eV**************@TK2MSFTNGP09.phx.gbl...
>> > Hi,
>> >
>> > I know this has been asked before, but reading the threads it is

still
> not
>> > entirely clear.
>> > Deciding which .Replace( ) to use when.
>> >
>> > Typically if I create a string in a loop I always use a

StringBuilder.
> At
>> > present I am
>> > porting a VB6 webclass app to VB.NET and therefore I am trying to

make
> it
>> > as
>> > efficent as possible via the new functionality of VB.NET.
>> >
>> > At present I have (in various places):
>> > variableX = variableX.Replace("a string", "another string") >> >
>> > In some cases the above variableX will have 4+ replaces virutally

one >> > after
>> > the
>> > other with 1 or 2 of the replacement strings having length > 100.
>> >
>> > This seems like the perfect candidate for StringBuilder.Replace

instead
> of
>> > String.Replace
>> > what does anybody think?
>> >
>> > Regards,
>> > Pete
>> >
>> >
>>
>>
>
>



Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve | last post by:
Hello. I am relatively new to using XML, but I'm trying to convert an xml document directly to a string or stringbuilder. I'm trying to use the XmlDocument class and Stringwriter classes, but I am...
2
by: ad | last post by:
Hello, if I try this ((StringBuilder)sb).Replace("a", "aa"); I get OutOfMemoryException raised if sb contains at least one "a"... It seems like StringBuilder 'seeker' doesn't move to the end...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
8
by: Guy | last post by:
Hi, I'm trying to run this code : strFileContentsHTML.Replace(vbLf, "<br>") strFileContentsHTML.Replace(vbCrLf, "<br>") strFileContentsHTML.Replace(vbCr, "<br>") It doesn't replace newline...
4
by: almurph | last post by:
Hi everyone, Can you help me please? Say you have hashtable of about 500 key/value pairs. This hashtable has to parse a word. If the word matches the key the then said word must be replaced by...
3
by: Morgan Cheng | last post by:
In P/Invoke situation, If some *out* parameter is LPWSTR, I can use string or StringBuilder. However, there is one problem about StringBuilder. By default, its Capacity is 16. If the returned...
5
by: int main(void) | last post by:
Hi all, Following is my attempt to write a string search and replace function. #include <stdio.h> #include <stdlib.h> #include <string.h>...
5
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of...
3
by: bharathreddy | last post by:
Everyone use the type String in their daily programming more often. In addition, most of people do a common mistake to choose between String and StringBuilder. In concatenation of Strings,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.