C# StringBuilder AppendFormat(String, Object, Object, Object)

Description

StringBuilder AppendFormat(String, Object, Object, Object) Appends the string returned by processing a composite format string, which contains zero or more format items, to this instance. Each format item is replaced by the string representation of either of three arguments.

Syntax

StringBuilder.AppendFormat(String, Object, Object, Object) has the following syntax.


public StringBuilder AppendFormat(
  string format,// w w w . ja  v a2  s  .c om
  Object arg0,
  Object arg1,
  Object arg2
)

Parameters

StringBuilder.AppendFormat(String, Object, Object, Object) has the following parameters.

  • format - A composite format string (see Remarks).
  • arg0 - The first object to format.
  • arg1 - The second object to format.
  • arg2 - The third object to format.

Returns

StringBuilder.AppendFormat(String, Object, Object, Object) method returns A reference to this instance with format appended. Each format item in format is replaced by the string representation of the corresponding object argument.

Example

The following example demonstrates the AppendFormat method.


/* w  ww  .j ava2 s  . com*/
using System;
using System.Text;
using System.Globalization;

class Sample 
{
    public static void Main() 
    {
        StringBuilder sb = new StringBuilder();
        int    var1   = 111;
        float  var2   = 2.22F;
        string var3   = "abcd";
        object[] var4 = {3, 4.4, 'X'};
    
        sb.AppendFormat("1) {0}", var1);
        Console.WriteLine(sb.ToString());
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding