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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Aug 8, 2013, 1:09 AM
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 SharmaPosted Aug 8, 2013, 1:26 AM
please follow this link:
http://support.microsoft.com/kb/306822/en-us