str-procedure = STR "(" str-item { "," str-item } ")" .
str-item = str-expression { ":" width-expression } .
str-expression = numeric-expression | string-expression .
This is the standard Pascal STR procedure that converts an expression to a string with optional width qualifier.
<width-expression>:
An optional qualifier (defaults to zero) which specifies the width in characters where the expression will be right adjusted; it is evaluated as BYTE: if the evaluation gives a larger value, a byte truncation warning is issued. A zero value means no adjustment.
If <width-expression> specifies more than the necessary digits needed to represent <str-expression>, spaces are inserted at left to adjust the string to <width-expression> digits.
If the <string-expression> maximum length is less than the number of generated digits, string truncation occurs.
Real numbers:
Writing REAL numbers is supported but formatting is limited in the current implementation: The number of decimals cannot be specified and the output is always 16 characters wide (or less if specified), in scientific format like "-1.234567890E+23". If positive the sign is a space.
If size is specified, the string is truncated from the left (e.g.: specifying 12 characters would output "-1.234567890", regardless of exponent.
It should be reserved to debug procedures.
VAR
SX2: string[2]; SX5: string[5];
W: word; I: integer; B: byte;
…
B := 3;
Str(123: B, SX2); // This will set SX2 to '23' regardless to B
W := $FFFF;
Str(W, SX5); // This will set SX5 to '65535'
I := -123;
Str(I: 5, SX5); // This will set SX5 to '- 123'