±if/else
Allows conditions for working on CSV data fields
Description
This command formulates a condition whether subsequently concatenated commands shall be carried out or not.It can only be used for data field commands, i.e. only for ±set, ±replace, ±remove, ±clear, ±trim, and ±regex.
Any other subsequent command results in an error.
The condition consists of a left operand, an comparing operator, and (mostly) a right operand.
Each operand may be a single [field], or an {expression}.
For numeric comparing operation, the operands must be enclosed in round brackets ([Field]) or (expression).
Before comparing, each expression and each field value will be resolved for each line, see Expressions and their Resolving. The comparison is then carried out with the resolved values.
The condition and the command are separated by a double delimiter (default delimiter is "/"). Do not insert the input/output prefix("+" or "-") again.
For all details about the available conditions, see also Filtering and Command Conditions.
Pattern
One condition and one conditional command looks as follows:
±if{Operand}Operator{Operand}//(Field Command)
There can also be an "else" case, that means that those subsequent commands shall be carried out if the condtion does not apply.
If there is an "else" command, it must be also separated by a double delimiter before and after.
±if{Operand}Operator{Operand}//(Field Command)//else//(Other Field Command)
Usage examples
- -if[Features]<#>{Leather}//set[Price]=([Price]+500)
- If the field "Features" (maybe the feature list of a car) contains the string "Leather" then the field "Price" is increased by 500.
- -if([Locations])>(3)//set[BigCompany]=Yes//else//set[BigCompany]=No
- If the field "Locations" (maybe the number of offices) contains a number that is greater than 3, then the field "BigCompany" is set to "Yes", otherwise it is set to "No".
In case you need more!
You can concatenate more than one condition and also more than one command.
In this case, each condition or command must again be separated by a double delimiter on each end. Make sure there are no whitespaces around the double delimiters when concatenating conditions and/or commands.
±if{Operand1}Operator1{Operand1}//if {Operand2}Operator2{Operand2}//(Field Command)
±if{Operand}Operator{Operand}//(Field Command1)//(Field Command2)//else//(Other Field Command1)//(Other Field Command2)