Not Equal to

Prev Next

Introduction

Basic rules to not-equal-to comparisons which are a bit more relaxed than the strictly not equal to comparison operator:

  • The number of operands on the right-hand-side is not limited to 1. A selection of multiple values may be specified as well as ranges.
  • Wildcards are supported in the right-hand operand if the value is a softquoted string (e.g. text inside single quotation marks).
  • When comparing sets, the same elements in both left and right hand side must exist, but they do not need to be in the same order
  • Dates, Booleans and numerals can be compared with strings if they have the same text value / string representation (e.g. if printed out). Example: '5' = 5, and 'true' = true are both true.
  • Comparing two void values will always return true.


Comparison not Equal to
1 If a numeral is compared with a string, then a string copy will be made of the numeral and both strings are compared.
2 If a date is compared with a string, then a string copy will be made of the date and both strings are compared. Depending on the state of the date, the format is "YYYY-MM-DD", "HH:II:SS", or "YYYY-MM-DD HH:II:SS".
3 If a boolean value is compared with a string, then a string copy will be made of the boolean value and both strings are compared.
4 Contents in both sets must be the same, but the ordering does not matter. E.g. {1,2,3} <> {3,2,1} returns false, however strictly comparison {1,2,3} != {3,2,1} returns true. Values (but not subsets) inside the sets are compared with the strictly not equal to != operator.

       echo("Basic comparisons:");

       a[0] = 3 <> 3;          // false
       a[1] = 5.1 <> 5;         // true
       a[2] = 5 <> 2,3,5,7;     // false
       a[3] = 5 <> 2,2+1,5,7;  // false
       a[4] = 5 <> 1..3;       // true
       a[5] = 5 <> 4..7;       // false
       a[6] = 5 <> 1..3,5,7;   // false
       a[7] = {1,2,3} <> {3,2,1}; // false

       for all variables( a[], x[] ) echo( x[] );

       echo("String with other types:");

       b[0] = 123 <> "123";         // false
       b[1] = '123' <> 123;         // false
       b[2] = false <> 'false';     // false
       b[3] = false <> 'False';     // true
       b[4] = date("2020-08-01") <> "2020-08-01";  // false
       b[5] = date("2020-08-01") <> "01.08.2020";  // true
       // The last one is 'true' because string representation of date is YYYY-MM-DD

       for all variables( b[], x[] ) echo( x[] );

       echo("Compare with wildcards:");

       c[0] = Hello World <> '*o*'; // Contains o, false
       c[1] = Hello World <> "*o*"; // Not equal to string "*o*", true
       c[2] = Hi <> 'Ha,Hi,Ho';     // Wildcard with commas, false
       c[3] = Hi <> Ha,Hi,Ho;       // Selection with commas, false

       for all variables( c[], x[] ) echo( x[] );
Basic comparisons:
false
true
false
false
true
false
false
false
String with other types:
false
false
false
true
false
true
Compare with wildcards:
false
true
false
false
Try it yourself: Open LAN_Features_not_equal_to.b4p in B4P_Examples.zip. Decompress before use.

Comparing Dates

Note that value of type date may assume 4 states: date only, time only, date and time combined and blank date (no value). Even for the same operator, the rules of calculating dates and numeric operands differ.
Comparison Equal to of dates
Note that in some cases, only the time or only the dates are compared.

       d [] = date('2020-07-14');
       dt[] = date('2020-07-14 12:30:00');
       t [] = date('12:30:00');
       o [] = date(''); // blank date
       dz[] = date('2020-07-14 12:30:01');

       a[0] = d[] <> dt[];   // false, dates same, time not compared
       a[1] = t[] <> dt[];   // false, times same, date not compared
       a[2] = d[] <> date("2020-07-15") - 1; // false
       a[3] = dt[] <> dz[];   // true (time differs)
       
       for all variables( a[], b[] ) echo( b[] );
false
false
false
true
Try it yourself: Open LAN_Features_not_equal_to_01.b4p in B4P_Examples.zip. Decompress before use.