Format
string Format(string fmt, ...)Description
Returns a formatted string, similar to sprintf.
The format string may contain any number of format specifiers which are replaced by the corresponding arguments.
Supported specifiers
| Specifier | Type | Description |
|-----------|------|-------------|
| %d, %i | int | Signed decimal integer |
| %u | int | Unsigned decimal integer |
| %f | float | Decimal floating point |
| %g | float | Shortest representation (fixed or scientific) |
| %e | float | Scientific notation |
| %s | string | String — any type is automatically converted |
| %% | — | Literal percent sign |
Width and precision modifiers are supported (e.g. %05d, %.2f, %-10s).
Parameter
- fmt - The format string.
- ... - Zero or more values to substitute into the format string.
Returns
The formatted string.
Example
void main()
{
string s1 = Format("Value: %d", 42); // "Value: 42"
string s2 = Format("Pi: %.2f", 3.14159); // "Pi: 3.14"
string s3 = Format("%s has %d items", "List", 5); // "List has 5 items"
string s4 = Format("Progress: %05d%%", 7); // "Progress: 00007%"
}