sprintf
Return a formatted string
&reftitle.description;
stringsprintf
stringformat
mixedvalues
Returns a string produced according to the formatting string
format.
&reftitle.parameters;
&strings.parameter.format;
values
&reftitle.returnvalues;
Returns a string produced according to the formatting string
format.
&reftitle.changelog;
&Version;
&Description;
8.0.0
This function no longer returns &false; on failure.
&reftitle.examples;
Argument swapping
The format string supports argument numbering/swapping.
]]>
&example.outputs;
However imagine we are creating a format string in a separate file,
commonly because we would like to internationalize it and we rewrite it as:
]]>
We now have a problem. The order of the placeholders in the
format string does not match the order of the arguments in the
code. We would like to leave the code as is and simply indicate
in the format string which arguments the placeholders refer to.
We would write the format string like this instead:
]]>
An added benefit is that placeholders can be repeated without adding
more arguments in the code.
]]>
When using argument swapping, the n$
position specifier must come immediately
after the percent sign (%), before any other
specifiers, as shown below.
Specifying padding character
]]>
&example.outputs;
Position specifier with other specifiers
]]>
&example.outputs;
sprintf: zero-padded integers
]]>
sprintf: formatting currency
]]>
&example.outputs;
sprintf: scientific notation
]]>
&example.outputs;
&reftitle.seealso;
printf
fprintf
vprintf
vsprintf
vfprintf
sscanf
fscanf
number_format
date