Parser Functions
The field dialog in Parser allows to enter a Function. Functions are also allowed in the "Default value" text box.
A function is a similar function as in Excel, but limited only to a list of supported ones listed below. An example of a function is:
'USD ' & ROUND(NUM({Total})*1.5, 2)
Basic syntax
Basic structures of a function are: numbers, strings, operators, references and functions.
Number is a regular decimal number (there's no difference between integer and decimal), with point (.) as a decimal separator (independent on the current culture settings). Negative numbers are prefixed with a hyphen (-).
Strings are enclosed in single quotes. If you need to include single quotes in a string, enter them twice ('').
Operators include: + (plus), - (minus), * (multiplication), / (division), = (equality), < (less than), > (greater than), & (string concatenation) and simple braces as precedence operator.
Reference operator allows you to get and work with values from other fields in the parsed document, reference syntax is {fieldname} (name of a field in curly braces). Let's say, if we had two fields in our definition: TotalNet and Total, we can add a new function field, entering "NUM({Total})-NUM({TotalNet})" into its function box. The field name is in fact an XPath from the parent's element point of view (in the final parsed XML document).
Functions consist of a function name (in upper case) and function arguments in braces. A function has 0 or more arguments, depending on the documentation below, and some arguments may be optional (enclosed in square brackets), thus using the default value.
SUM(field) function
Returns the sum of all field fields. If any of the field is not a number, the function outputs an error.
COUNT(field) function
Returns the number (count) of field fields.
ROUND(num, [digits=0]) function
Returns num number rounded the digits decimal places. If digits is negative, the function rounds to the other side (e.g. ROUND(123, -1) returns 120).
NUM(text) function
Tries to convert text into number. Returns 0 if conversion fails.
TEXT(num) function
Converts num into text (string representation).
LENGTH(text) function
Returns the length of text. If text is a number, it is converted to string first.
FIND(sub, text, [startAt=0]) function
Returns the first zero-based index of sub within text, starting at startAt. Returns -1 if sub is not found.
SUBSTR(text, startAt, [length]) function
Returns a substring of text starting at startAt and length characters long. If length is omitted, the function returns everything until the end of text.
IF(cond, ifTrue, ifFalse) function
Returns value of ifTrue if cond is true or non-zero, otherwise returns ifFalse.
SPLIT(text, delim, index) function
Splits text by delim delimiter characters and returns substring number index. If delim has more than one character, then text is split by any of the characters.
MATCHES(regex, text) function
Returns true if text matches regular expression regex, false otherwise. See MSDN for regular expression reference.
REGEX(regex, text, group) function
Returns the group number group of regex matched against text. If text doesn't match regex or group exceeds the total number of matched groups the result is empty string.
REPLACE(text, oldtext, newtext) function
Returns text where all occurrences of oldtext are replaced with newtext.
FORMAT(format, num) function
Returns a string-formatted number num, as specified in format. See MSDN for format string specification.