Solved

StringBuilder

Posted on 2006-11-18
1
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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