System.Text Namespace StringBuilder Class
Appends a formatted string, which contains zero or more format specifications, to this instance. Each format specification is replaced by the string representation of a corresponding object argument.
[ VB ] <Serializable> Overloads Public Function AppendFormat ( _ ByVal format As String, _ ByVal arg As Object, _ ByVal arg1 As Object, _ ByVal arg2 As Object _ ) As StringBuilder [ C# ] [Serializable] public StringBuilder AppendFormat ( string format, object arg, object arg1, object arg2 ); [ C++ ] [Serializable] public: StringBuilder* AppendFormat ( String* format, Object* arg, Object* arg1, Object* arg2 ); [ JScript ] public Serializable function AppendFormat ( format : String, arg : Object, arg1 : Object, arg2 : Object ) : StringBuilder;
A reference to this instance with format appended. Any format specification in format is replaced by the string representation of the corresponding object argument.
Exception Type | Condition |
---|---|
ArgumentNullException | Any of the object parameters is a null reference ( Nothing in Visual Basic ). |
FormatException | format is invalid. |
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 to format and FormatString is a format string. If argN implements IFormattable then argN.Format ( format, null ) provides the formatting; otherwise ToString provides the formatting. If arg, arg1, or arg2 is a null reference ( Nothing in Visual Basic ) then an empty string is used in its place.
To Pad With Spaces: You can 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.
If the string assigned to format is "Thank you for your purchase of {0:####} copies of Microsoft® .NET ( Core Reference )." and arg 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 string assigned to format is "Brad's dog has {0,-8:G} fleas." and arg is an Int16 with the value 42, then the return value will be "Brad's dog has 42 fleas."
StringBuilder Members StringBuilder.AppendFormat Overload List
Check out related books at Amazon
© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note