Solved

StringBuilder

Posted on 2006-11-18
1
339 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get Client IP on RDS - VB.NET 15 68
Get number of Files in Directory and Sub Directories 2 48
vb.net 1 month apart 11 35
Very Large data in MYSQL 7 73
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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