473,395 Members | 2,443 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,395 software developers and data experts.

string or Stringbuilder??

Shall I use stringbuilder in the following statement? why?

string devInfo =
"<DeviceInfo>" +
"<Toolbar>False</Toolbar>" +
"<MarginLeft>0in</MarginLeft>" +
"<MarginRight>0in</MarginRight>" +
"<MarginTop>0in</MarginTop>" +
"<MarginBottom>0in</MarginBottom>" +
"<PageHeight>" +
myVariable1.toString() +
"</PageHeight>" +
"<PageWidth>" +
myVariable2.toString();

thanks for your help.
Ali
Nov 16 '05 #1
4 1105
ALI-R wrote:

Shall I use stringbuilder in the following statement? why?

string devInfo =
"<DeviceInfo>" +
"<Toolbar>False</Toolbar>" +
"<MarginLeft>0in</MarginLeft>" +
"<MarginRight>0in</MarginRight>" +
"<MarginTop>0in</MarginTop>" +
"<MarginBottom>0in</MarginBottom>" +
"<PageHeight>" +
myVariable1.toString() +
"</PageHeight>" +
"<PageWidth>" +
myVariable2.toString();

thanks for your help.
Ali


String should be just fine. StringBuilder is good when you are adding to the
string and/or otherwise causing it to resize numerous times (e.g. in a loop).
Nov 16 '05 #2
Is this inside of a loop?

If this is executed once, a StringBuilder might not be necessary as the
performance gain might not be substantial. Although there are times when
StringBuilder are beneficial, they may not always be necessary.

"ALI-R" <ne****@microsoft.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Shall I use stringbuilder in the following statement? why?

string devInfo =
"<DeviceInfo>" +
"<Toolbar>False</Toolbar>" +
"<MarginLeft>0in</MarginLeft>" +
"<MarginRight>0in</MarginRight>" +
"<MarginTop>0in</MarginTop>" +
"<MarginBottom>0in</MarginBottom>" +
"<PageHeight>" +
myVariable1.toString() +
"</PageHeight>" +
"<PageWidth>" +
myVariable2.toString();

thanks for your help.
Ali

Nov 16 '05 #3
ALI-R <ne****@microsoft.com> wrote:
Shall I use stringbuilder in the following statement? why?

string devInfo =
"<DeviceInfo>" +
"<Toolbar>False</Toolbar>" +
"<MarginLeft>0in</MarginLeft>" +
"<MarginRight>0in</MarginRight>" +
"<MarginTop>0in</MarginTop>" +
"<MarginBottom>0in</MarginBottom>" +
"<PageHeight>" +
myVariable1.toString() +
"</PageHeight>" +
"<PageWidth>" +
myVariable2.toString();


No - that ends up becoming one single String.Concat call with four
parameters - a single constant string "<DeviceInfo><Toolbar>[...]",
myVariable1.ToString(), "</PageHeight><PageWidth>" and
myVariable2.ToString().

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
No,it is not in the loop.

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Is this inside of a loop?

If this is executed once, a StringBuilder might not be necessary as the
performance gain might not be substantial. Although there are times when
StringBuilder are beneficial, they may not always be necessary.

"ALI-R" <ne****@microsoft.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
Shall I use stringbuilder in the following statement? why?

string devInfo =
"<DeviceInfo>" +
"<Toolbar>False</Toolbar>" +
"<MarginLeft>0in</MarginLeft>" +
"<MarginRight>0in</MarginRight>" +
"<MarginTop>0in</MarginTop>" +
"<MarginBottom>0in</MarginBottom>" +
"<PageHeight>" +
myVariable1.toString() +
"</PageHeight>" +
"<PageWidth>" +
myVariable2.toString();

thanks for your help.
Ali


Nov 16 '05 #5

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

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
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...
5
by: Dave | last post by:
I'm receiving info from a com port into a string. I gradually process the string which constantly shortens it. The question is how long can a string be before I need to write some info to disk...
12
by: Tee | last post by:
String Builder & String, what's the difference. and when to use which ? Thanks.
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...
12
by: Richard Lewis Haggard | last post by:
I thought that the whole point of StringBuilder was that it was supposed to be a faster way of building strings than string. However, I just put together a simple little application to do a...
26
by: Hardy Wang | last post by:
Hi all, I know it is better to handle large string with a StringBuilder, but how does StringBuilder class improve the performance in the background? Thanks! -- WWW:...
10
by: Mo | last post by:
Hi, I am trying to write a code to build a string 768 characters long. This string is going to be written to a file which is then read by another application. The format of the string is already...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
34
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.