Version: Unity 7.0 Alpha (7000.0)
Language : English
Populate strings with data using Sources
Dictionary source

Default source

Select an argument by its numeric index, the same way String.Format does.

The Default source extracts an argument by index, similarly to String.Format. It examines the current selector, and if the selector parses as an integer that is a valid index into the arguments passed to Smart.Format, it returns the argument at that index. No further selectors are considered for that placeholder.

The selector only resolves as an index when it is the first selector in the placeholder and has no operator, matching the way String.Format treats {0}. The selector must parse as an integer and be within the number of arguments provided, otherwise the source does not handle it and the next source is tried.

In the following example, the Default source resolves 0 in the selector {0.Name} to the first argument. Then, another source (such as the Properties source) resolves Name against that value.

When no index is given, for example {Name}, the argument at index 0 is used by the other sources.

Smart String Arguments Result
{0} {1} {2} 1, 2, 3 1 2 3
{1} {1} {2} {0} 1, 2, 3 2 2 3 1
Player {0} scored {1} points "Potato", 155 Player Potato scored 155 points
Player {0.Name} scored {0.Points} points new { Name = "One", Points = 100 } Player One scored 100 points
Smart.Format("{0} {1} {2}", 1, 2, 3);                          // "1 2 3"
Smart.Format("Player {0} scored {1} points", "Potato", 155);   // "Player Potato scored 155 points"

Additional resources

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