Appends a composite format string : StringBuilder « Development Class « C# / C Sharp






Appends a composite format string

 

using System;
using System.Text;
using System.Globalization;

class Sample 
{
    static StringBuilder sb = new StringBuilder();

    public static void Main() 
    {
        int    var1   = 111;
        float  var2   = 2.22F;
        string var3   = "abcd";
        object[] var4 = {3, 4.4, 'X'};
    
        Console.WriteLine("StringBuilder.AppendFormat method:");
        sb.AppendFormat("1) {0}", var1);
        Console.WriteLine(sb);
        sb.AppendFormat("2) {0}, {1}", var1, var2);
        Console.WriteLine(sb);
        sb.AppendFormat("3) {0}, {1}, {2}", var1, var2, var3);
        Console.WriteLine(sb);
        sb.AppendFormat("4) {0}, {1}, {2}", var4);
        Console.WriteLine(sb);
        CultureInfo ci = new CultureInfo("es-ES", true);
        sb.AppendFormat(ci, "5) {0}", var2);
        Console.WriteLine(sb);
    }
}

   
  








Related examples in the same category

1.Create a StringBuilder which hold 100 characters.
2.Length and Indexer
3.Use StringBuilder to reverse a string
4.using the StringBuilder methods Replace, Insert, Append, AppendFormat, and Remove:
5.String ConcatenationString Concatenation
6.illustrates reading and writing string dataillustrates reading and writing string data
7.Replace char in a StringBuilder object
8.Replace Char with String
9.Represents a mutable string of characters.
10.Create StringBuilder class using the specified capacity.
11.Create StringBuilder class that starts with a specified capacity and can grow to a specified maximum.
12.Create a StringBuilder class using the specified string.
13.Create StringBuilder class using the specified string and capacity.
14.Create StringBuilder class from the specified substring and capacity.
15.Appends various data to StringBuilder
16.Appends the default line terminator to the end of the current StringBuilder object.
17.Gets or sets the maximum number of characters that can be contained
18.Removes all characters from the current StringBuilder instance.
19.Copies characters to a destination Char array.
20.Inserts various data types
21.Removes the specified range of characters from this instance.
22.Replaces all occurrences of a specified character in this instance with another specified character.