Mono Class Library: System.Text.StringBuilder Overview | Members

System.Text.StringBuilder.AppendFormat Method

Appends the specified string to the current instance, with the format specifications in that string being replaced with the appropriately formatted string values of the specified objects. [Edit]

public StringBuilder AppendFormat (string format, object arg0, object arg1)

Parameters

format
A string containing zero or more format specifications. [Edit]
arg0
The first object to be formatted. Can be a null reference. [Edit]
arg1
The second object to be formatted. Can be a null reference. [Edit]

Returns

The current instance after the operation has occurred. [Edit]

Exceptions

TypeReason
ArgumentNullExceptionformat is a null reference. [Edit]
FormatExceptionformat is invalid. [Edit]

Remarks

This method appends the formatted copy of the specified string to the current instance. If an object referenced in the format string is null , an empty string is used in its place.

Note: This version of StringBuilder.AppendFormat(string, object) is equivalent to StringBuilder.AppendFormat(string, object)( null , format, new Object[] {arg0, arg1} ). For more information on the format specification, see the string class overview.

[Edit]

Example

C# Example
using System;
using System.Text;

public class StringBuilderTest {
  public static void Main() {

     StringBuilder sb = new StringBuilder("The high ");
     Console.WriteLine( sb.AppendFormat("temperature today was {0} {1}.", "very", "high") ); 
  }
}
   

The output is

The high temperature today was very high.

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0