Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

StringBuilder

Posted on 2006-11-18
1
Medium Priority
?
363 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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