String FORMAT Operator

The : operator is a binary (infix) string FORMAT operator. The : operator expects a string left hand operand and either an integer or string right hand operand.

The format specifier within the format string (the left hand operand) determins if the right hand operand is to be coerced to an integer or coerced to a string before the FORMAT operator is applied.

 

syntax:

	<left_expr> : <right_expr>

<left_expr> and <right_expr> are refered to as the left and right operand respectively and may themselves be simple values or complex expressions.

Format specifiers

The format string is a literal string containing an embedded conversion code. The conversion code is prefixed by the special character % which is optionally followed by:

'-' char     which indicates left field justified
'number' which indicates minimum field width
'.' char which seperates the minimum field width from the maximum field width
'number' which indicates maximum field width
then one of the characters
d    decial
o unsigned octal (without leading zero)
u unsigned decial
c character
s string
% literal % char
e.g.
	"%d" : 16			yields "16"
	"%4d" : 16			yields "  16"
	"0x%04X" : 31			yields "0x001F"

	"hello %d jack" : 16		yields "hello 16 jack"
	"hello %s jack" : 16		yields "hello 16 jack"
	"hello %s jack" : "dear"	yields "hello dear jack"

	"%c" : 65			yields "A"

	"%3.3s" : "hello world"		yields "hel"

	"%% J=%d" : 27			yields "% J=27"