sprintf

Description

The sprintf() function creates a character string by formatting the supplied arguments according to the formatting commands in a format control string. The resulting character string is returned in result.

The format control string controls the formation of the character string that is returned in result. It consists of two types of information: actual content and format command characters. The format command characters are used to insert and format the supplied arguments. The number of format command characters in the format control string must match the number of supplied arguments. In other words, if there are three formatting commands in the format control string, then three function arguments must be supplied. Otherwise, an error is generated.

For more information on format command characters, see Format Commands.

Syntax

result = sprintf (controlstring [,expression1, …]);

Arguments

controlstring Required. Character string that contains the format control string that is used to generate the formatted string.
expression1 - Optional. Character string and integer values to substitute into the format control string.

Return Values

result contains the formatted character string.

Example

In this example,

result = sprintf ("System administrator Ids: %s %s %s", "Adm1", "Adm2", "Adm3");

the character string System administrator Ids: Adm1 Adm2 Adm3 is assigned to result.

See Also

fprintf, print(), printf, syslog