Format fields

Format fields are used in strings with functions str.format, out, paste, mes, end, and operator F. A format field is a special character, or several characters, preceded with %. The whole string is followed by variables or other values that will replace the format fields. The format fields tell how to format the values.

 

Syntax

%[flags][width][.precision][h|l|I64|L]type

 

type - character that determines whether the argument is interpreted as a character, a string, or a number.

flags - character or characters that control justification of output and adding of signs, blanks, decimal points, and octal and hexadecimal prefixes.

width - number that specifies the minimum number of characters in output.

precision - number that specifies the maximum number of characters used for all or part of the output field, or the minimum number of digits used for integer values.

h, l, I64, L - character that specifies argument size. For arguments of type long, use I64. Note: here I is uppercase i, not lowercase L.

 

Remarks

%% in format strings are replaced to % and not interpreted as format fields.

 

Almost everything is the same as with C/C++ printf, sprintf and similar functions. Differences:

 

Example

int i=50
str s="stringvar"
double d=3.1415926535897932384626433832795
str f
f.format("variables: i=%i, s=''%s'', d=%.10G" i s d)
out f ;;variables: i=50, s="stringvar", d=3.141592654