±if/else/end
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, ±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.
Pattern
One condition and one conditional command looks as follows:
±if{Operand}Operator{Operand}//(Field Command)
There can also be an
If there is an
±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)
It is also possible to nest conditions and commands.
This is done by starting a new if-condition group inside commands. The inner group will then generally have to end using
Here is this depicted with colors (outer group: white, inner group: yellow).
±if{Operand1}Operator1{Operand1}//Field Command1)//if{Operand2}Operator2{Operand2}//(Field Command2)//end //(Field Command 3)
To make nesting more clear, you might add a
This is required when the nested condition/command group starts immediately after the conditions of the outer group, so the inner and the outer
Here is this depicted with colors (outer group: white, inner group: yellow).
±if{Operand1}Operator1{Operand1}//if/n{Operand2}Operator2{Operand2}//(Field Command2)//end //(Field Command 3)
You can also nest condition/commmand groups in the
Here is this again depicted with colors (outer group: white, inner group: yellow).
±if{Operand1}Operator1{Operand1}//Field Command1)//else//if{Operand2}Operator2{Operand2}//(Field Command2)//end //(Field Command 3)
And the inner condition/command group can have an
Here is this again depicted with colors (outer group: white, inner group: yellow).
±if{Operand1}Operator1{Operand1}//Field Command1)//else//if{Operand2}Operator2{Operand2}//(Field Command2)//else//(Field Command4)//end //(Field Command 4)
Usage Examples
...