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 string values of the specified array of objects, formatted in accordance with the formatting object returned by the specified IFormatProvider. [Edit]

public StringBuilder AppendFormat (IFormatProvider provider, string format, params object[] args)

Parameters

provider
A IFormatProvider that supplies a formatting object that provides culture specific formatting information. Can be a null reference. [Edit]
format
A string containing zero or more format specifications. [Edit]
args
A object array to be formatted. [Edit]

Returns

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

Exceptions

TypeReason
ArgumentNullExceptionformat or args 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.

The format parameter is embedded with zero or more format specifications of the form, {N [, M ][: formatString ]}, where N is a zero-based integer indicating the argument to be formatted, M is an optional integer indicating the width of the region to contain the formatted value, and formatString is an optional string of formatting codes.

Note: 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() {

     string a = "very";
     string b = "very";
     string c = "high";

     StringBuilder sb = new StringBuilder("The high ");
     Console.WriteLine(sb.AppendFormat(null, "temperature today was {0}, {1} {2}.", a, b, c) ); 
  }
}
   

The output is

The high temperature today was very, very high.

Requirements

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