C# StringBuilder AppendFormat(String, Object, Object)
Description
StringBuilder AppendFormat(String, 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 two arguments.
Syntax
StringBuilder.AppendFormat(String, Object, Object)
has the following syntax.
public StringBuilder AppendFormat(
string format,/*w w w . java2s. com*/
Object arg0,
Object arg1
)
Parameters
StringBuilder.AppendFormat(String, 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.
Returns
StringBuilder.AppendFormat(String, 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.
using System;/*from w ww . j a v a 2 s. c o m*/
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);
sb.AppendFormat("2) {0}, {1}", var1, var2);
Console.WriteLine(sb.ToString());
}
}
The code above generates the following result.