&sprintf - Formatted string construction
&sprintf format args
The &sprintf function (or &spr in it's abbreviated form) provides a mechanism to generated a formatted string, similar to the 'C' programming language sprintf(2) function.
The &sprintf function is generally used where a number of different sources of information have to be converted and joined together to form a new string. It is possible to do this using &cat(4), but it does become complicated if the number of strings to be spliced together is greater than about 4, sprintf alleviates these problems and results in faster execution. Where only two, or three strings are to be concatenated &cat provides better execution times.
The &sprintf function produces a string construct for the format and a caller determined number of arguments args (variable arguments). The format string may contain special '%' formatting commands to insert strings and numbers into the base format string. The format for the '%' commands is "%nc" where:-
n
c
d (Decimal integer)
n (Repeat String)
s (String)
x (Hexadecimal integer)
%
The &sprintf function may be nested (i.e. a string argument to &sprintf may be the result of another &sprintf invocation). Although this type of construct is not generally required !!
The following examples show how the command may be used:-
set-variable %result &sprintf "Foo [%s%s]" "a" "b"
generates "Foo [ab]"
set-variable %result &sprintf "Foo [%n%s]" 10 "a" "b"
generates "Foo [aaaaaaaaaab]".
set-variable %result &sprintf "[%d] [%3d] [%x] [%3x]" 10 11 12 13
generates "[10] [ 11] [c] [ d]"
It is the callers responsibility to ensure that the correct number of arguments is supplied to match the requested formatting string. The results are undefined if an incorrect number of arguments are supplied.
(c) Copyright JASSPA 1999
Last Modified: 1998/09/02
Generated On: 1999/12/01