Default formatter
Format a value the same way String.Format does.
Read time 1 minuteLast updated 6 days ago
Format a value the same way String.Format does.
The Default formatter is the fallback formatter. It converts a value to text using the standard .NET formatting logic. Apply it explicitly with the name , but in most cases it applies implicitly when no other formatter handles the value. Numeric and date format strings such as , , and work exactly as they do with .
dCN2dString.FormatCultural formatting, such as currency symbols and date order, follows the active culture. Pass a CultureInfo (or any IFormatProvider) to to control it; otherwise the current culture is used.
Smart.Formatvar amount = 1234567.89; // "The cost is $1,234,567.89" Smart.Format(new CultureInfo("en-US"), "The cost is {0:C}", amount); // "The cost is 1 234 567,89 €" Smart.Format(new CultureInfo("fr-FR"), "The cost is {0:C}", amount);
Smart String | Argument | Result |
|---|---|---|
| | The cost is $1,234,567.89 |
| | The cost is 1 234 567,89 € |
| a | Today is 11/8/2021 |
| a | Today is 08/11/2021 |
The formatter applies the value's IFormattable.ToString implementation when the format provider supplies one, then falls back to the value's .
ToStringA custom ICustomFormatter from the format provider takes precedence, so you can plug in your own formatting.
When the format contains nested placeholders, those are formatted first instead of the value being formatted directly.