what is the difference between string and stringbuilder in c# with example

Posted by Gow.Net under C# on 3/16/2012 | Points: 10 | Views : 51549 | Status : [Member] | Replies : 9
what is the difference between string and stringbuilder in c# with example

gowthaman8870226416


Responses

Posted by: Patel28rajendra on: 3/16/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

see following link

http://www.techtamasha.com/difference-between-string-and-stringbufferstringbuilder-in-java/28

http://www.javaworld.com/javaworld/jw-03-2000/jw-0324-javaperf.html


If it helps then Mark as Answer
Thanks



R D Patel

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/16/2012 [Member] Silver | Points: 25

Up
0
Down

Hi Gow,
Refer to This:
http://www.dotnetfunda.com/forums/thread8425-difference-bw-string-and-string-builder.aspx

Thanks,
Sanjay

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kulprachi84 on: 3/16/2012 [Member] Starter | Points: 25

Up
0
Down
System.String is immutable.(Non updatable)
System.StringBuilder is mutable (Updatable)
Using StringBuilder, various string operations can be performed in most effective manner.


Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/20/2012 [Member] Bronze | Points: 25

Up
0
Down
string is immutable whereas stringbuilder is mutable, for ex:

string s="abc";
s="lmn";
s="xyz";
s string always create new object of string type in memory.
but when you use string builder class, it will update string at one place in memory doesnt create new space in memory.

whenever you are creating a string by multiple strings then use string builder rather than string class.

Thanks,
Rajni Shekhar

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 11/22/2012 [Member] Bronze | Points: 25

Up
0
Down

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.we say "Strings are immutable".
6.. system.string is non updatable.

stringbuilder
7.string
everytime a object has to be created for Operations like
append,Insert etc. at runtime

1. system.stringbuilder is updateble.
2.string builder is faster than the string object.
3.String builder is more efficient in case large amount of string operations have to be perform.
4.String builder is mutable means we can able to re size the memory size
5.Insertion is done on the existing string.
6.System.stringbuilder is used to dynamic strings

Example
class Program
{
static void Main(string[] args)
{
//for example:
string str = "hello"; //Creates a new object when we concatenate any other words along with str variable it does not actually modify the str variable, instead it creates a whole new string.
str = str + " to all";
Console.WriteLine(str);
StringBuilder s = new StringBuilder("Hi");
s.Append(" To All");
Console.WriteLine(s);
Console.Read();
}
}

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 11/22/2012 [Member] Bronze | Points: 25

Up
0
Down
Please mark as answer if it helpful to you..That helps others who search the same..

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prasokoc on: 3/26/2014 [Member] Starter | Points: 25

Up
0
Down
this post may help you to understand more about string and string builder

http://dotnetstock.com/uncategorized/difference-abstract-class-interface-c-asp-net http://dotnetstock.com/uncategorized/difference-abstract-class-interface-c-asp-net

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mrkraju999 on: 11/6/2015 [Member] Starter | Points: 25

Up
0
Down
Here you go

http://www.dotnetlearners.com/blogs/view/180/Difference-between-String-and-StringBuilder.aspx

http://www.dotnetlearners.com/tutorial/angularjs/17/angularjs-tutorial-introuduction-to-angularjs

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhupentiwari on: 11/9/2015 [Member] Starter | Points: 25

Up
0
Down
Hi,
When we do any operation on string using String Class it creates new instance. Where String Builder update existing instance only.





Thanks n Regards
Bhupendra Tiwari

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response