473,385 Members | 1,757 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.

Why isn't there an StringBuilder.Append overload with StringBuilder as argument?

Why isn't there an StringBuilder.Append() overload with a StringBuilder as
argument?
Is there a reason that I missed?
Jul 22 '05 #1
9 1798
I think there isn't because it would be useless. Now you can do:

....
stringBuilder2.Append(stringBuilder1.ToString());
....

I find no reason why one need such method.
"cody" <de********@gmx.de> escribió en el mensaje
news:eG**************@TK2MSFTNGP10.phx.gbl...
Why isn't there an StringBuilder.Append() overload with a StringBuilder as
argument?
Is there a reason that I missed?

Jul 22 '05 #2
> I think there isn't because it would be useless. Now you can do:

...
stringBuilder2.Append(stringBuilder1.ToString());
...

I find no reason why one need such method.


Your "reason" would make all of the existing 19 overloads of StringBuilder
"useless".
The problem is that stringBuilder1.ToString() creates a new string which I
want to avoid.
Jul 22 '05 #3
How do you build the other one ? You could perhaps reuse it ie. using a
single string builder rather than creating separately two of them and then
combining them ?
--

"cody" <de********@gmx.de> a écrit dans le message de
news:eU**************@TK2MSFTNGP14.phx.gbl...
I think there isn't because it would be useless. Now you can do:

...
stringBuilder2.Append(stringBuilder1.ToString());
...

I find no reason why one need such method.
Your "reason" would make all of the existing 19 overloads of

StringBuilder "useless".
The problem is that stringBuilder1.ToString() creates a new string which I
want to avoid.

Jul 22 '05 #4
Sure I could do that. But Iam asking why StringBuilder doesn't support that.
There must be a technical reason. Maybe it has something to do with
threadsafety.
"Patrice" <no****@nowhere.com> schrieb im Newsbeitrag
news:u5**************@TK2MSFTNGP10.phx.gbl...
How do you build the other one ? You could perhaps reuse it ie. using a
single string builder rather than creating separately two of them and then
combining them ?
--

"cody" <de********@gmx.de> a écrit dans le message de
news:eU**************@TK2MSFTNGP14.phx.gbl...
I think there isn't because it would be useless. Now you can do:

...
stringBuilder2.Append(stringBuilder1.ToString());
...

I find no reason why one need such method.


Your "reason" would make all of the existing 19 overloads of

StringBuilder
"useless".
The problem is that stringBuilder1.ToString() creates a new string which I want to avoid.


Jul 22 '05 #5
StringBuilder works internally with a large string, inserting data at an
incrementing position. For example, Append(bool value) calls return
this.Append(value.ToString()), where Append(string value) does the real
appending. Append(object value) works in the same way.

So if there would be a Append(StringBuilder value), it would internally
still call Append(value.ToString()), thus making it equal to call
Append(myStringBuilder.ToString()).

cody wrote:
Why isn't there an StringBuilder.Append() overload with a StringBuilder as
argument?
Is there a reason that I missed?

Jul 22 '05 #6
Simon Svensson <ta*****@tant102.mine.nu> wrote:
StringBuilder works internally with a large string, inserting data at an
incrementing position. For example, Append(bool value) calls return
this.Append(value.ToString()), where Append(string value) does the real
appending. Append(object value) works in the same way.

So if there would be a Append(StringBuilder value), it would internally
still call Append(value.ToString()), thus making it equal to call
Append(myStringBuilder.ToString()).


Not quite equal - after calling myStringBuilder.ToString(), any appends
to myStringBuilder have to create a new string, whereas with suitable
support in StringBuilder, that wouldn't be necessary.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 22 '05 #7
Rather conceptual than technical IMO. It was just intended to build a whole
string using a single StringBuilder ;-)

For example if you push further the use of several stringbuilders and
merging them, you are on a path that is not that different to the initial
situation for strings (you'll finally ends up with copying strings to a
memory location just to move them at some other place shortly).

--
Patrice

"cody" <de********@gmx.de> a écrit dans le message de
news:ut**************@TK2MSFTNGP14.phx.gbl...
Sure I could do that. But Iam asking why StringBuilder doesn't support that. There must be a technical reason. Maybe it has something to do with
threadsafety.
"Patrice" <no****@nowhere.com> schrieb im Newsbeitrag
news:u5**************@TK2MSFTNGP10.phx.gbl...
How do you build the other one ? You could perhaps reuse it ie. using a
single string builder rather than creating separately two of them and then
combining them ?
--

"cody" <de********@gmx.de> a écrit dans le message de
news:eU**************@TK2MSFTNGP14.phx.gbl...
> I think there isn't because it would be useless. Now you can do:
>
> ...
> stringBuilder2.Append(stringBuilder1.ToString());
> ...
>
> I find no reason why one need such method.

Your "reason" would make all of the existing 19 overloads of StringBuilder
"useless".
The problem is that stringBuilder1.ToString() creates a new string

which I want to avoid.



Jul 22 '05 #8
Maybe you're right, it sounds quite logical, but I suspect there are
situations where it actually could be useful.
"Patrice" <no****@nowhere.com> schrieb im Newsbeitrag
news:uA**************@TK2MSFTNGP15.phx.gbl...
Rather conceptual than technical IMO. It was just intended to build a whole string using a single StringBuilder ;-)

For example if you push further the use of several stringbuilders and
merging them, you are on a path that is not that different to the initial
situation for strings (you'll finally ends up with copying strings to a
memory location just to move them at some other place shortly).

--
Patrice

"cody" <de********@gmx.de> a écrit dans le message de
news:ut**************@TK2MSFTNGP14.phx.gbl...
Sure I could do that. But Iam asking why StringBuilder doesn't support

that.
There must be a technical reason. Maybe it has something to do with
threadsafety.
"Patrice" <no****@nowhere.com> schrieb im Newsbeitrag
news:u5**************@TK2MSFTNGP10.phx.gbl...
How do you build the other one ? You could perhaps reuse it ie. using a single string builder rather than creating separately two of them and then combining them ?
--

"cody" <de********@gmx.de> a écrit dans le message de
news:eU**************@TK2MSFTNGP14.phx.gbl...
> > I think there isn't because it would be useless. Now you can do:
> >
> > ...
> > stringBuilder2.Append(stringBuilder1.ToString());
> > ...
> >
> > I find no reason why one need such method.
>
> Your "reason" would make all of the existing 19 overloads of
StringBuilder
> "useless".
> The problem is that stringBuilder1.ToString() creates a new string

which
I
> want to avoid.
>
>



Jul 22 '05 #9
Have you checked ToString ? Unless you abuse it it should be still quite
quick anyway (this is *repeated* allocations that kills you with strings so
a single copy shouldn't be that harmfull).

You could easily compare the ToString approach and the single StringBuilder
approach and see if it makes a difference in your case...

Happy coding...
--

Patrice

"cody" <de********@gmx.de> a écrit dans le message de
news:Of**************@TK2MSFTNGP12.phx.gbl...
Maybe you're right, it sounds quite logical, but I suspect there are
situations where it actually could be useful.
"Patrice" <no****@nowhere.com> schrieb im Newsbeitrag
news:uA**************@TK2MSFTNGP15.phx.gbl...
Rather conceptual than technical IMO. It was just intended to build a whole
string using a single StringBuilder ;-)

For example if you push further the use of several stringbuilders and
merging them, you are on a path that is not that different to the initial
situation for strings (you'll finally ends up with copying strings to a
memory location just to move them at some other place shortly).

--
Patrice

"cody" <de********@gmx.de> a écrit dans le message de
news:ut**************@TK2MSFTNGP14.phx.gbl...
Sure I could do that. But Iam asking why StringBuilder doesn't support

that.
There must be a technical reason. Maybe it has something to do with
threadsafety.
"Patrice" <no****@nowhere.com> schrieb im Newsbeitrag
news:u5**************@TK2MSFTNGP10.phx.gbl...
> How do you build the other one ? You could perhaps reuse it ie.
using a > single string builder rather than creating separately two of them

and then
> combining them ?
> --
>
> "cody" <de********@gmx.de> a écrit dans le message de
> news:eU**************@TK2MSFTNGP14.phx.gbl...
> > > I think there isn't because it would be useless. Now you can do:
> > >
> > > ...
> > > stringBuilder2.Append(stringBuilder1.ToString());
> > > ...
> > >
> > > I find no reason why one need such method.
> >
> > Your "reason" would make all of the existing 19 overloads of
> StringBuilder
> > "useless".
> > The problem is that stringBuilder1.ToString() creates a new string

which
I
> > want to avoid.
> >
> >
>
>



Jul 22 '05 #10

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

Similar topics

20
by: Alvin Bruney | last post by:
On the advice of a user, I've timed stringbuilder v string. Here are the results. Here are the numbers: Total # queries 3747 Time in Milliseconds StringBuilder: String...
12
by: | last post by:
I know how to use a StringBuilder, which supposedly does not create a new copy of it each time you modify it contents by adding or removing text. But, I wonder how does it do that internally ? I...
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
1
by: Sagaert Johan | last post by:
Hi I am construncting a string containing some control chars (STX/ETX) I noticed that adding a byte with value 2 is the same as adding a character '2' ??? How can i solve this problem ?...
3
by: todorov-fkt | last post by:
Hello Provided the following code: string temp = "Short string"; // 12 chars StringBuilder sb = new StringBuilder(); sb.Append(temp, 0, 30); How many characters is the string in sb? 12 or is...
6
by: Paulb1us | last post by:
I am writing a DataTable to a file using a stringbuilder. The Format of the date in the table is like this: '12/20/04' But after I write it to the file it ads the time: '12/20/04 12:00:00 AM' ...
9
by: Peter Row | last post by:
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...
9
by: cody | last post by:
Why isn't there an StringBuilder.Append() overload with a StringBuilder as argument? Is there a reason that I missed?
8
by: Soulless | last post by:
I am trying to implement the stringbuilder class by taking a LARGE multiline text box and looping through the lines and build a string and include \r\n in it. I get : Index was outside the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.