NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

String.Format (String, Object, Object)

Replaces zero or more format specifications with the appropriately formatted value of an object.

[Visual Basic]
Overloads Public Shared Function Format( _
   ByVal format As String, _
   ByVal arg0 As Object, _
   ByVal arg1 As Object _
) As String
[C#]
public static string Format(
   string format,
   object arg0,
   object arg1
);
[C++]
public: static String* Format(
   String* format,
   Object* arg0,
   Object* arg1
);
[JScript]
public static function Format(
   format : String,
   arg0 : Object,
   arg1 : Object
) : String;

Parameters

format
A string containing zero or more format specifications.
arg0
The first object to be formatted.
arg1
The second object to be formatted.

Return Value

A copy of the string is returned after replacing any format specifications with the appropriately formatted value.

Exceptions

Exception Type Condition
ArgumentNullException If the string is null.
FormatException If string is invalid.

Remarks

The format specifications are embedded within a String and are of the form {N:FormatString}, where N is a zero-based number indicating the argument that is to be formatted and FormatString is a format string. If argN implements IFormattable then argN.Format (format, null) provides the formatting; otherwise argN.ToString() provides the formatting. If arg0 or arg1 is null then an empty string is used in its place.

To Pad With Spaces: It is possible to define a region within the String argument in which the formatted value can be left or right justified. The format specification has an optional integer field: {N[,M]:FormatString}. The magnitude of M indicates the minimum number of spaces for the region and the sign of M indicates whether the value should be left (negative values) or right (positive values) justified within the region.

ToString() is Used if the Format String is Omitted: The format string within a format specification is optional: {N[,M][:FormatString]}. When FormatString is omitted, the ToString() method of the argument specified by N is used to replace the format specification. If M is given, then the result of ToString() is padded with spaces as described above.

Example

If the String assigned to format is "Thank you for your purchase of {0:####} copies of Better Basket Weaving." and arg0 is an Int16 with the value 123, then the return value will be:

"Thank you for your purchase of 123 copies of Better Basket Weaving."
If the String assigned to format is "Brad's dog has {0, -8:G} fleas." and arg0 is an Int16 with the value 42,
then the return value will be:
"Brad's dog has 42      
fleas."

See Also

String Class | String Members | System Namespace | String.Format Overload List | Object | IFormattable