Utilities
Sub-string extraction
The {SUBSTR} code is used to extract a sub-string from a text. The first parameter is the text to process, the next is a (zero based) index of the first character to extract, and the optional third parameter is the number of characters to extract. If the number of characters is not specified, all characters until the end of the text will be extracted.
A negative index counts from the end of the text, e.g. -2 starts at the second to last character. A negative number of characters leaves out that many characters at the end of the text. An index beyond the end of the text results in an empty text.
For the following examples, assume that the variable MyVariable contains the value ABCDEFGH, and that the current year is 2024:
{SUBSTR;{VARIABLE;MyVariable};3} -> DEFGH
{SUBSTR;{VARIABLE;MyVariable};3;1} -> D
{SUBSTR;{VARIABLE;MyVariable};0;2} -> AB
{SUBSTR;{VARIABLE;MyVariable};-2} -> GH
{SUBSTR;{VARIABLE;MyVariable};0;-2} -> ABCDEF
{SUBSTR;{YEAR};3;1} -> 4
Arithmetic expressions
The {EXPR} code evaluates an integer arithmetic expression and prints the result. The first parameter is the expression, which can itself contain dynamic text codes, e.g. variables or table columns. The supported operators are +, -, * and /, with the usual precedence, and parentheses can be used for grouping. Division is integer division, i.e. the result is truncated towards zero. Division by zero is an error.
The result can be formatted using the number formatting parameters, e.g. WIDTH= and FORMAT=.
For the following examples, assume that the variable Count contains the value 12, and that the current year is 2024:
{EXPR;{VARIABLE;Count}*2} -> 24
{EXPR;({VARIABLE;Count}+3)/4} -> 3
{EXPR;{YEAR}-2000;WIDTH=3} -> 024
{EXPR;{YEAR}-2020;FORMAT={A;B;C;D;E}} -> D
{NUMFMT} is an older name for {EXPR}, and is still accepted for backward compatibility.