Loading...
 

Format elements

Format elements

For the instructions String, MLString, Left, Right, Mid and Truncate, a format list (as a string) can be specified in the first parameter. The format list corresponds - with some restrictions - to the first parameter of the function sprintf of the C standard library.

For format elements of the mould

         %flags width .precision type          % (position) flags width .precision type 

data from the stack is inserted at the appropriate position - the format specification controls the conversion of the data element into the substring to be inserted.
All other characters in the format list are adopted unchanged.

Note: For the percentage sign % itself, %% must be written.

A format element always begins with the character % and at least one character for the data type. The other elements (position, flags, width, precision) are optional.

Type character of a format element

Type Value of stack is converted to Result
d integer integer (with sign if necessary)
i integer integer (with sign if necessary)
u integer (absolute value) integer (unsigned)
o integer (absolute value) Number in octal representation (without sign)
x integer (absolute value) Number in hexadecimal representation with the digits 0...9abcdef (without sign)
X integer (absolute value) Number in hexadecimal representation with the digits 0...9ABCDEF (unsigned)
s Character string Character string
f not supported -
g not supported -

position

By specifying a numerical position (starting at 1), the nth argument can be bound to this placeholder. The binding between argument and placeholder is done without specifying the position in ascending order (analogous to the assignment of formats to columns in SetFormat). Explicit specification allows arguments to be referenced multiple times in a format string or arguments to be skipped. In the SetFormat analogy, the position corresponds to the explicit COLUMN specification.


Flags

Flag Meaning Standard
- left-aligned alignment right-aligned
+ values > 0 with + sign only values < 0 with -
0 Fill field with 0 fill up with blank
# Prefix for octal and hexadecimal numbers without prefix

width - field width
is a non-negative number and determines the minimum number of characters; i.e. the substring to be inserted is never shorter. If necessary, fill characters are inserted - depending on the flags(- and 0) described above.
The length of the substring cannot be limited by specifying a field width!

Instead of a number, the character * can be specified. The value for the field width is then also taken from the stack.

precision
consists of the dot . followed by a non-negative number which determines the maximum number of characters. In contrast to the specification width , the length of the substring is limited here. Instead of a number, the character * can be specified. The value for precision is then also taken from the stack.

For the types f and g not currently supported by InstantView®, precision determines the number of decimal places.


Examples:

InstantView® code Result
23 24 String("x=%d and y=%5d") "x=23 und y=   24"
23 String("x=%05d") "x=00023"
1 2 String("%d + %(1)d = %d")"1 + 1 = 2"
23 7 String("x=%0*d ") "x=0000023"
"abcde" string("%10s") "     abcde"
"abcde" string("%.10s") "abcde"
"abcde" string("%-10s") "abcde     "
"abcde" string("%010s") "00000abcde"
"abcdefgijkl..." String("%.5s") "abcde"
30 string("h=%x") "h=1e"
30 string("h=%X") "h=1E"
30 String("h=%#x") "h=0x1e"
CreateTransObject(CX_TIME) String("Time: %s", TF_SECONDS)"Zeit: 13.38.47"