How to remove all characters from StringBuilder in C# Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report StringBuilder.Clear Method is used to remove all the characters from the current StringBuilder instance. Syntax: public System.Text.StringBuilder Clear (); It returns an StringBuilder object whose length will be zero. Note: Clear is a convenience method that is equivalent to setting the Length property of the current instance to 0 (zero). Calling the Clear method does not modify the current instance's Capacity or MaxCapacity property. Example: csharp // C# program to demonstrate // the Clear() Method using System; using System.Text; class GFG { // Main Method public static void Main(String[] args) { // Creating a StringBuilder object StringBuilder sb1 = new StringBuilder("GeeksforGeeks"); // printing the length of "GeeksforGeeks" Console.WriteLine("The String is: {0} \nTotal characters -- {1}", sb1.ToString(), sb1.Length); // using the method sb1.Clear(); // printing the length of "GeeksforGeeks" Console.WriteLine("The String is: {0} \nTotal characters -- {1}", sb1.ToString(), sb1.Length); sb1.Append("This is C# Tutorials."); // printing the length of "GeeksforGeeks" Console.WriteLine("The String is: {0} \nTotal characters -- {1}", sb1.ToString(), sb1.Length); } } Output: The String is: GeeksforGeeks Total characters -- 13 The String is: Total characters -- 0 The String is: This is C# Tutorials. Total characters -- 22 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.clear?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article How to remove all characters from StringBuilder in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-method CSharp-StringBuilder-Class Similar Reads How to find the Capacity of a StringBuilder in C# StringBuilder.Capacity Property is used to get or set the maximum number of characters that can be contained in the memory allocated by the current instance. Syntax: public int Capacity { get; set; }Return Value: This property will return the maximum number of characters that can be contained in the 2 min read How to create the StringBuilder in C# StringBuilder() constructor is used to initialize a new instance of the StringBuilder class which will be empty and will have the default initial capacity. StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutabl 2 min read StringBuilder.Chars[] Property in C# StringBuilder.Chars[Int32] Property is used to get or set the character at the specified character position in this instance. Syntax: public char this[int index] { get; set; } Here, the index is the position of the character. Property Value: This property returns the Unicode character at position in 2 min read C# | Removing all entries from the StringDictionary StringDictionary.Clear method is used to remove all the entries from the StringDictionary. Syntax: public virtual void Clear (); Exception: This method will give the NotSupportedException if the StringDictionary is read-only. Example: CSHARP // C# code to remove all entries // from the StringDiction 2 min read How to find the MaxCapacity of a StringBuilder in C# StringBuilder.MaxCapacity Property is used to get the maximum capacity of this instance. Syntax: public int MaxCapacity { get; } Property Value: It returns the maximum number of characters of type System.Int32 this instance can hold. Note: The maximum capacity for this implementation is Int32.MaxVal 1 min read Like