Demonstrating StringBuilder AppendFormat : StringBuffer StringBuilder « Language Basics « C# / C Sharp






Demonstrating StringBuilder AppendFormat

Demonstrating StringBuilder AppendFormat
    using System;
    using System.Text;

   class StringBuilderAppendFormat {
      static void Main(string[] args)
      {
         StringBuilder buffer = new StringBuilder();
         string string1, string2;

         string1 = "This {0} costs: {1:C}.\n";

         object[] objectArray = new object[ 2 ];

         objectArray[ 0 ] = "Software";
         objectArray[ 1 ] = 1234.56;
         buffer.AppendFormat( string1, objectArray );

         string2 = "Number:{0:d3}.\n" +
            "Number right aligned with spaces:{0, 4}.\n" +
            "Number left aligned with spaces:{0, -4}.";

         buffer.AppendFormat( string2, 5 );
         Console.WriteLine(buffer.ToString());
      }
   } 

           
       








Related examples in the same category

1.StringBuilder EnsureCapacity methodStringBuilder EnsureCapacity method
2.StringBuilder's properties for different constructorsStringBuilder's properties for different constructors
3.StringBuilder append: int, char, string, boolean at specific positionStringBuilder append: int, char, string, boolean at specific position
4.StringBuilder AppendFormat() method to add a formatted string containing a floating point number to myStringBuilderStringBuilder AppendFormat() method to add a formatted string containing a floating point number to myStringBuilder
5.StringBuilder Insert(): insert strings into myStringBuilderStringBuilder Insert(): insert strings into myStringBuilder
6.Use the Remove() method to remove part of StringBuilderUse the Remove() method to remove part of StringBuilder
7.Replace(): replace part of myStringBuilderReplace(): replace part of myStringBuilder
8.ToString(): convert myStringBuilder to a stringToString(): convert myStringBuilder to a string
9.illustrates the use of StringBuilder objectsillustrates the use of StringBuilder objects
10.StringBuffer: Replacing CharactersStringBuffer: Replacing Characters
11.StringBuilder foreach StringBuilder foreach
12.StringBuilder: write lineStringBuilder: write line