sprintf

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, please see Other Programming Considerations.

result = sprintf (controlstring [,expression1, …]);
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.

result contains the formatted character string.

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.

fprintf, print(), printf, syslog