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