Solved

StringBuilder

Posted on 2006-11-18
1
335 Views
Last Modified: 2010-04-23
What is StringBuilder? Could you give me some samples on how to use this class? No links please.
0
Comment
Question by:VBdotnet2005
1 Comment
 
LVL 5

Accepted Solution

by:
DEEPESH earned 250 total points
ID: 17973809
Everytime you do chnages in string variable, it will lead into creating new object.
For example
dim str as string

str ="Hello"
Now suppose i append something in this string
str =str & "Deepesh"

Result of this will be creation of a new object, where hello deepesh will reside.
Because a new object is created with every assignment, there is a slight
overhead when doing this repeatedly. This is called immutable.

The string builder class provides a more efficient way to repeatedly add string
on to a string that to without creartion of new object,
that means it require less overhead.

StringBuilder is much faster when you do string operations. String takes
less space in memory.

The StringBuilder class represents a mutable string of characters.
It's called mutable because it can be modified once it has been created by using Append, Insert, Remove, and Replace methods.

Dim builder As StringBuilder = New StringBuilder("Hello", 20)
builder.Append(" Deepesh")
Msgbox builder
result will be Hello Deepesh

Simalrly you can use Remove method,insert method and replace method.


So to summarise
String type is immutable. There is no way to modify an already created
string object. When you, for example, appending a character or another
string to a string, a new combined string is actually created every time.
StringBuilder is mutable and works much faster when you need to modify it's
content.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now