cmp (Compare)
The function $cmp compares two values with each other and returns a truth value as result. A compare operator specifies how the values are compared with each other.
Syntax
$cmp(left,operator,right[,mode])
Parameter
Name |
Description |
left |
The left comparison value. |
operator |
Defines the compare operator. The following operators are available:
|
right |
The right comparison value. |
mode |
An optional compare mode that specifies whether the comparison should be numeric or text-based. The following modes are available:
|
Return value
Returns true if the condition for the comparison 'left operator right' is fulfilled, otherwise false.
Example
Syntax |
Result |
Remarks |
$cmp(2,>,11,n) |
false |
The number '2' is not greater than the number '11'. |
$cmp(2,>,11,s) |
true |
In a text-based comparison, '2' is greater than '11' because the ASCII character code of '2' is greater than that of '1'. |
$cmp(2,>,11) |
true |
Same reason as above. s is the default mode. |
$cmp(0,==,0) |
true |
|
$cmp(Hallo,==,Hallo) |
true |
|
$cmp(hallo,==,Hallo) |
false |
Case sensitive. |
$cmp(Hallo,reg,/^hallo$/i) |
true |
Regular case insensitive comparison. |