User Guide : Using Content Extraction Language : Variables and Fields : Variable Typing and Conversion
Share this page             
Variable Typing and Conversion
Variables and fields may be (floating point) numbers, or strings, or both.
The way a variable is interpreted depends on the way it is used. If a variable is assigned a numeric value, it will be treated as a number. If a variable is assigned a string value, it will be treated as a string.
counter = 5;
# counter is a numeric variable
text = "Counter is equal to ";
# text is a string variable
output = text + counter;
# output is both a string and a numeric # variable, since it has been assigned a # string and a number
All variables start out as string variables until a value is assigned. To force a variable to be treated as a number, assign it a numeric value. This is usually done in the begin block (refer to the BEGIN pattern in the Patterns section for more information):
Comparisons written in CXL are performed as follows:
If both expressions to the left and right of the comparison operator evaluate to a string then a string comparison is made.
A numeric comparison is performed if one or both of the expressions evaluate to a number.
In comparisons, uninitialized variables have the numeric value 0 and the string value "" (the null, or empty, string).