Format objects into a string
String sprintf (String format, ...);
String_Type Sprintf (String_Type format, ..., Integer_Type n)
Both functions create a string based on the supplied format
string and the remaining arguments to the call, in
a similar manner to the C function sprintf.
The difference between the two routines is that
Sprintf must also be sent the number of items to format
(the n parameter above).
The format string is a C library sprintf style format
descriptor. Briefly, the format string may consist of ordinary
characters (not including the % character), which are copied
into the output string as-is, and a conversion specification
introduced by the % character. The % character must be
followed by at least one other character to specify the conversion:
s value is a string
f value is a floating point number
e print float in exponential form, e.g., 2.345e08
g print float as e or g, depending upon its value
c value is an ascii character
% print the percent character
d print a signed decimal integer
u print an unsigned decimal integer
o print an integer as octal
X print an integer as hexadecimal
S convert value to a string and format as string
Note that %S is a S-Lang extension which will cause the value
to be formatted as string. In fact, sprintf("%S",x) is
equivalent to sprintf("%s",string(x)).
s = sprintf("%f is greater than %f but %s is better than %s\n", PI, E,
"Cake" "Pie");
s = Sprintf("%f is greater than %f but %s is better than %s\n", PI, E,
"Cake" "Pie", 4);
The final argument to Sprintf is the number of items to format; in
this case, there are 4 items.
- slangrtl
-
_apropos,
_print_stack,
_slang_guess_type,
char,
integer,
message,
pack,
putenv,
set_float_format,
sscanf,
strcat,
string,
verror,
vmessage
|