Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Posts Tagged ‘clear

Ways to clear stringbuilder in C#

with 2 comments

There are no clear method straightaway to clear the string stored in stringbuilder class.

So there are alternatives to do that.

sbObject.Remove(0,sbObject.Length);

or you can do the below also

string strObject= sbObject.ToString();
sbObject.Replace(strObject,"");

 
But Microsoft people woken up and put the Clear() function in .NET 4.0 🙂
 
Advertisements

Written by Manish

February 6, 2010 at 11:08 am

Posted in .NET

Tagged with , ,