asp.net.ph

String.Format Method ( String, Object )

System Namespace   String Class


Replaces the format specification in a specified String with the textual equivalent of the value of a specified Object instance.

[ VB ]
<Serializable>
Overloads Public Shared Function Format ( _
   ByVal format As String, _
   ByVal arg0 As Object _
) As String

[ C# ]
[ Serializable ]
public static string Format (
   string format,
   object arg0
);

[ C++ ]
[ Serializable ]
public: static String* Format (
   String* format,
   Object* arg0
);

[ JScript ]
public Serializable
static function Format (
   format : String,
   arg0 : Object
) : String;

Parameters

format
A String containing zero or more format specifications.
arg0
An Object to be formatted.

Return Value

A copy of format in which the first format specification has been replaced by the String equivalent of arg0.

Exceptions


Exception Type Condition
ArgumentNullException format or arg0 is a null reference ( Nothing in Visual Basic ).
FormatException The format specification in format is invalid.

-or-

The number indicating an argument to be formatted ( N ) is less than zero, or larger than or equal to the length of the args array.


Remarks

The format parameter is embedded with zero or more format specifications of the form, { N [ , M ] [ : formatString ] }, where:

  • N is a zero-based integer indicating the argument to be formatted.
  • M is an optional integer indicating the width of the region to contain the formatted value, padded with spaces. If the sign of M is negative, the formatted value is left-justified in the region; if the sign of M is positive, the value is right-justified.
  • formatString is an optional string of formatting codes.

If argN implements IFormattable, then argN.Format ( formatString, null ) provides formatting; otherwise argN.ToString ( ) provides formatting. If argN is null, then an empty string is used in its place.If formatString is omitted, the ToString ( ) method of the argument specified by N provides formatting.

If the value of format is, "Thank you for your purchase of {0:####} copies of Microsoft® .NET ( Core Reference ).", and arg0 is an Int16 with the value 123, then the return value will be:

"Thank you for your purchase of 123 copies of Microsoft® .NET ( Core Reference )."

If the value of format is, "Brad's dog has {0,-8:G} fleas.", arg0 is an Int16 with the value 42, ( and in this example, underscores represent padding spaces ) then the return value will be:

"Brad's dog has 42______ fleas."

See Also

String Members   String.Format Overload List   Object   IFormattable Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph