Definition: | string s = sprintf(string st, object x) |
Description: | This is exactly the same as printf(), except that the output is returned as a string, rather than being sent to a file or device. st is a format string, x is the value or sequence of values to be formatted. printf(fn, st, x) is equivalent to and in fact implemented as puts(fn, sprintf(st, x)). |
Comments: | Some typical uses of sprintf() are:
1. Converting numbers to strings. 2. Creating strings to pass to system(). 3. Creating formatted error messages that can be passed to a common error message handler. |
Example: |
s = sprintf("%08d", 12345) -- s is "00012345" |
See Also: | printf, value, sprint, get, system |