sformat

fnchar[] sformat(Char, Args...)(return scope char[] buf, scope const(Char)[] fmt, Args args)

Converts its arguments according to a format string into a buffer. The buffer has to be large enough to hold the formatted string.

The second version of sformat takes the format string as a template argument. In this case, it is checked for consistency at compile-time.

Parameters

bufthe buffer where the formatted string should go
fmta format string
argsa variadic list of arguments to be formatted
Charcharacter type of fmt
Argsa variadic list of types of the arguments

Returns

A slice of buf containing the formatted string.

Throws

A RangeError if buf

isn't large enough to hold the formatted string and a FormatException if formatting did not succeed.

Note

In theory this function should be @nogc. But with the current

implementation there are some cases where allocations occur:

  • An exception is thrown.
  • A custom toString function of a compound type allocates.
fnchar[] sformat(alias fmt, Args...)(char[] buf, Args args) if (isSomeString!(typeof(fmt)))

ditto