Name
FormatStr -- compose a C-style formatted string (V5.0)
Synopsis
s$ = FormatStr(fmt$, ...)
Function
This function can be used to compose a C-style formatted string with Hollywood. You have to pass the formatting template in the first argument and you have to pass one additional argument for every token in the template. Hollywood supports most of the tokens of C's printf specification. Here is a list of all tokens that are currently supported:

%c
ASCII character
%d
Signed decimal integer
%i
Same as %d
%o
Unsigned octal integer
%u
Unsigned decimal integer
%x
Unsigned hexadecimal integer (lower case notation)
%X
Unsigned hexadecimal integer (upper case notation)
%e
Floating point number in exponential notation
%E
Same as %e but in upper case exponential notation
%f
Floating point number in normal notation
%g
Floating point number in %e or %f format (whichever is more compact)
%G
Same as %g but uses upper case if exponential notation is used
%s
String

You can also specify a width field before the token to limit the number of characters that the specific token should add to the string. For example, if you use the token %.6x, the hexadecimal number generated by this function will always have 6 digits.

As the percent sign is used for tokens by this function, you need to escape it if you just want to append a percent sign to the string. In that case simply use a double percent sign (%%).

Inputs
fmt$
formatting template containing one or more tokens (see above for supported tokens)
...
additional arguments (one for each token present in fmt$)
Results
s$
resulting string
Example
a = 128
s$ = FormatStr("The number " .. a .. " is $%x in hexadecimal notation", a)
The code above converts the number 128 to hexadecimal notation.


a = 255
s$ = FormatStr("The number " .. a .. " is $%.6x in RGB notation", a)
The code above converts the number 255 into a 6 digit hexadecimal value which is often used to specify RGB colors.

Show TOC