String::Format Method
Replaces each format item in a specified string with the text equivalent of a corresponding object's value.
This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.
| Name | Description | |
|---|---|---|
|
Format(String, Object) | Replaces one or more format items in a specified string with the string representation of a specified object. |
|
Format(String, array<Object>) | Replaces the format item in a specified string with the string representation of a corresponding object in a specified array. |
|
Format(IFormatProvider, String, array<Object>) | Replaces the format item in a specified string with the string representation of a corresponding object in a specified array. A specified parameter supplies culture-specific formatting information. |
|
Format(String, Object, Object) | Replaces the format items in a specified string with the string representation of two specified objects. |
|
Format(String, Object, Object, Object) | Replaces the format items in a specified string with the string representation of three specified objects. |
Each overload of the Format method uses the composite formatting feature to include zero-based indexed placeholders, called format items, in a composite format string. At run time, each format item is replaced with the string representation of the corresponding argument in a parameter list. If the value of the argument is nullptr, it is replaced with String::Empty. For example, the following call to the Format method includes a format string with three format items, {0}, {1}, and {2}, and an argument list with three items.
A format item has the following syntax:
{index[,alignment][ : formatString] }Brackets denote optional elements. The opening and closing brackets are required. A format item has the following elements:
Note |
|---|
To include a literal opening or closing brace in the format string, see the "Escaping Braces" section in the Composite Formatting article. |
The following example illustrates how to use optional elements in format items to produce formatted output.
Note