StringBuilder.ToString() : StringBuilder « System.Text « C# / C Sharp by API






StringBuilder.ToString()

  

   using System;
   using System.Text;

   class StringBuilderFeatures
   {
      static void Main(string[] args)
      {
         StringBuilder buffer =new StringBuilder( "Hello, how are you?" );

         string output = "buffer = " + buffer.ToString() +
            "\nLength = " + buffer.Length +
            "\nCapacity = " + buffer.Capacity;

         buffer.EnsureCapacity( 75 );

         output += "\n\nNew capacity = " +buffer.Capacity;

         // truncate StringBuilder by setting Length property
         buffer.Length = 10;

         output += "\n\nNew length = " +
            buffer.Length + "\nbuffer = ";

         // use StringBuilder indexer
         for ( int i = 0; i < buffer.Length; i++ )
            output += buffer[ i ];

         Console.WriteLine( output);
      }
   }

   
    
  








Related examples in the same category

1.new StringBuilder()
2.StringBuilder.Append
3.StringBuilder.AppendFormat
4.StringBuilder.Capacity
5.StringBuilder.GetType()
6.StringBuilder.Insert
7.StringBuilder.Length
8.StringBuilder.Remove
9.StringBuilder.Replace