MSDN Documentation

String.Format Method

public static string Format(string format, object arg0)

Converts the specified array of objects to their equivalent string representation, using the formatting information of the current culture, and writes the resulting string to a new string.

Parameters

  • format
    A composite format string that contains placeholders for zero or more arguments.
  • arg0
    The object to format.

Returns

A string that consists of the specified strings and the formatted replacement of the format placeholders.

Remarks

The String.Format method is used to create a formatted string. It substitutes the format items in a specified string with the string representation of the corresponding objects in an argument list.

For more detailed information about format items and their usage, refer to the Standard Numeric Format Strings and Custom Format Strings documentation.

Example


using System;

public class Example
{
    public static void Main()
    {
        string name = "World";
        string greeting = String.Format("Hello, {0}!", name);
        Console.WriteLine(greeting); // Output: Hello, World!

        int day = 25;
        string month = "December";
        string date = String.Format("Today is {0} {1}.", day, month);
        Console.WriteLine(date); // Output: Today is 25 December.
    }
}
                    

See Also