asp.net.ph

String.Format Method ( IFormatProvider, String, Object [ ] )

System Namespace   String Class


Replaces the format specification in a specified String with the textual equivalent of the value of a corresponding Object instance in a specified array. A specified parameter supplies culture-specific formatting information.

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

[ C# ]
[ Serializable ]
public static string Format (
   IFormatProvider provider,
   string format,
   params object [ ] args
);

[ C++ ]
[ Serializable ]
public: static String* Format (
   IFormatProvider* provider,
   String* format,
   Object* args __gc [ ]
);

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

Parameters

provider
An IFormatProvider that supplies culture-specific formatting information.
format
A String containing zero or more format specifications.
args
An Object array containing zero or more objects to be formatted.

Return Value

A copy of format in which the format specifications have been replaced by the String equivalent of the corresponding instances of Object in args.

Exceptions


Exception Type Condition
ArgumentNullException format or args is a null reference ( Nothing in Visual Basic ).
FormatException 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 arg [ 0 ] 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.", arg [ 0 ] 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   IFormatProvider 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