String/StringBuilder
Provide an example of how you can use the 'string' and 'StringBuilder' classes to accomplish a task.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Posted Aug 7, 2013, 9:09 PM EDT
string testStirng = "Hello World";
testStirng += "! Welcome !";
MessageBox.Show(testStirng);
StringBuilder testStringBuilder = new StringBuilder();
testStringBuilder.Append("Hello World");
testStringBuilder.Append("! Welcome !");
MessageBox.Show(testStringBuilder.ToString());
The output will be same.
But there is a difference in the internal implementation of string and stringbuilder.
Difference Between String and String
String
1.Its a class used to handle strings.
2.Here concatenation is used to combine two strings.
3.String object is used to concatenate two strings.
4.The first string is combined to the other string by creating a new copy in the memory as a string object, and then the old
string is deleted
5.That is why "Strings are immutable".
6. Slower
String Builder
1.This is also the class used to handle strings.
2.Here Append method is used.
3.Here, Stringbuilder object is used.
4.Insertion is done on the existing string.
5.Usage of StringBuilder is more efficient in case large amounts of string manipulations have to be performed.
6. Faster
For more information, refer here http://www.c-sharpcorner.com/Blogs/3778/
Sunny SharmaRank #223 · 11.1K reputationPosted Aug 7, 2013, 9:26 PM EDT
please follow this link:
http://support.microsoft.com/kb/306822/en-us