Clib.sprintf()
syntax: |
Clib.sprintf(str, formatString[, variables ...]) |
where: |
str - to hold the formatted output.
formatString - string that specifies the final format.
variables - values to be converted to and formatted as a string.
|
return: |
number - characters written to string on success, else EOF on failure.
|
description: |
This method writes output to the string variable specified by str according to formatString, and returns the number of characters written or EOF if there was an error. The parameter formatString may contain character combinations indicating how following parameters are to be written. The parameter str need not be previously defined. It will be created large enough to hold the result.
The format string may contain character combinations indicating how following parameters are to be treated. Characters are handled normally until a percent character, %, is reached. The percent % indicates that a value is to be written from the variables following the format string. See Clib.printf() for a complete description of formatString.
|
see: |
|
example: |
// Each of the following lines shows // a sprintf example followed // by the resulting string.
Clib.sprintf(testString, "I count: %d %d %d.",1,2,3)
// "I count: 1 2 3"
var a = 1; var b = 2; Clib.sprintf(testString, "%d %d %d", a, b, a+b)
// "1 2 3" |