Solved

StringBuilder

Posted on 2006-11-18
1
324 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

18 Experts available now in Live!

Get 1:1 Help Now