Version: Unity 7.0 Alpha (7000.0)
Language : English
Conditional formatter
Is Match formatter

Default formatter

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 d, but in most cases it applies implicitly when no other formatter handles the value. Numeric and date format strings such as C, N2, and d work exactly as they do with String.Format.

Cultural formatting, such as currency symbols and date order, follows the active culture. Pass a CultureInfo (or any IFormatProvider) to Smart.Format to control it; otherwise the current culture is used.

var 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 {0:C} 1234567.89 (US culture) The cost is $1,234,567.89
The cost is {0:C} 1234567.89 (French culture) The cost is 1 234 567,89 €
Today is {0:d} a DateTime (US culture) Today is 11/8/2021
Today is {0:d} a DateTime (French culture) 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 ToString.

A 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.

Additional resources

Conditional formatter
Is Match formatter
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961