4D v14.3

Comparison Operators

Home

 
4D v14.3
Comparison Operators

Comparison Operators  


 

 

The tables in this section show the comparison operators as they apply to string, numeric, date, time, pointer and picture with metadata expressions (you cannot use them with array or BLOB type expressions). An expression that uses a comparison operator returns a Boolean value, either TRUE or FALSE.

Note: You can compare two pictures using the Equal pictures command.

OperationSyntaxReturnsExpressionValue
EqualityString = StringBoolean"abc" = "abc"True
"abc" = "abd"False
InequalityString # StringBoolean"abc" # "abd"True
"abc" # "abc"False
Greater thanString > StringBoolean "abd" > "abc"True
"abc" > "abc"False
Less thanString < StringBoolean"abc" < "abd"True
"abc" < "abc"False
Greater than or equal toString >= StringBoolean "abd" >= "abc"True
"abc" >= "abd"False
Less than or equal toString <= StringBoolean "abc" <= "abd"True
"abd" <= "abc"False
Contains keywordString % StringBoolean "Alpha Bravo" % "Bravo"True
"Alpha Bravo" % "ravo"False
Picture % StringBooleanPicture_expr % "Mer"True (*)

(*) If the keyword "Mer" is associated with the picture stored in the picture expression (field or variable).
Important: Additional information about string comparisons are provided at the end of this section.

OperationSyntaxReturnsExpressionValue
EqualityNumber = NumberBoolean10 = 10True
10 = 11False
InequalityNumber # NumberBoolean10 #11True
10 # 10False
Greater thanNumber > NumberBoolean11 > 10True
10 > 11False
Less thanNumber < NumberBoolean10 < 11True
11 < 10False
Greater than or equal toNumber >= NumberBoolean11 >= 10True
10 >= 11False
Less than or equal toNumber <= NumberBoolean10 <= 11True
11 <= 10False

OperationSyntaxReturnsExpressionValue
EqualityDate = DateBoolean!1/1/97! =!1/1/97!True
!1/20/97! =!1/1/97!False
InequalityDate # DateBoolean!1/20/97! # !1/1/97!True
!1/1/97! # !1/1/97!False
Greater thanDate > DateBoolean!1/20/97! > !1/1/97!True
!1/1/97! > !1/1/97!False
Less thanDate < DateBoolean!1/1/97! < !1/20/97!True
!1/1/97! < !1/1/97!False
Greater than or equal toDate >= DateBoolean!1/20/97! >=!1/1/97!True
!1/1/97!>=!1/20/97!False
Less than or equal toDate <= DateBoolean!1/1/97!<=!1/20/97!True
!1/20/97!<=!1/1/97!False

OperationSyntaxReturnsExpressionValue
EqualityTime = TimeBoolean?01:02:03? = ?01:02:03?True
?01:02:03? = ?01:02:04?False
InequalityTime # TimeBoolean?01:02:03? # ?01:02:04?True
?01:02:03? # ?01:02:03?False
Greater thanTime > TimeBoolean?01:02:04? > ?01:02:03?True
?01:02:03? > ?01:02:03?False
Less thanTime < TimeBoolean?01:02:03? < ?01:02:04?True
?01:02:03? < ?01:02:03?False
Greater than or equal toTime >= TimeBoolean?01:02:03? >=?01:02:03?True
?01:02:03? >=?01:02:04?False
Less than or equal toTime <= TimeBoolean?01:02:03? <=?01:02:03?True
?01:02:04? <=?01:02:03?False

With:

  ` vPtrA and vPtrB point to the same object
 vPtrA:=->anObject
 vPtrB:=->anObject
  ` vPtrC points to another object
 vPtrC:=->anotherObject
OperationSyntaxReturnsExpressionValue
EqualityPointer = PointerBooleanvPtrA = vPtrBTrue
vPtrA = vPtrCFalse
InequalityPointer # PointerBooleanvPtrA # vPtrCTrue
vPtrA # vPtrBFalse

  • Strings are compared on a character-by-character basis (except in the case of searching by keywords, see below).
  • When strings are compared, the case of the characters is ignored; thus, "a"="A" returns TRUE. To test if the case of two characters is different, compare their character codes. For example, the following expression returns FALSE:
     Character code("A")=Character code("a") // because 65 is not equal to 97
  • When strings are compared, diacritical characters are compared using the system character comparison table of your computer. For example, the following expressions return TRUE:
     "n"="ñ"
     "n"="Ñ"
     "A"="å"
      // and so on
  • Unlike other string comparisons, searching by keywords looks for “words” in “texts”: words are considered both individually and as a whole. The % operator always returns False if the query concerns several words or only part of a word (for example, a syllable). The “words” are character strings surrounded by “separators,” which are spaces and punctuation characters and dashes. An apostrophe, like in “Today's”, is usually considered as part of the word, but will be ignored in certain cases (see the rules below). Numbers can be searched for because they are evaluated as a whole (including decimal symbols). Other symbols (currency, temperature, and so on) will be ignored.
     "Alpha Bravo Charlie"%"Bravo" // Returns True
     "Alpha Bravo Charlie"%"vo" ` Returns False
     "Alpha Bravo Charlie"%"Alpha Bravo" // Returns False
     "Alpha,Bravo,Charlie"%"Alpha" // Returns True
     "Software and Computers"%"comput@" // Returns True

    Notes:
    - 4D uses the ICU library for detecting keywords. For more information about the rules implemented, please refer to the following address:http://www.unicode.org/unicode/reports/tr29/#Word_Boundaries.
    - In the Japanese version, instead of ICU, 4D uses Mecab by default for detecting keywords. For more information, please refer to Support of Mecab (Japanese version).

  • The wildcard character (@) can be used in any string comparison to match any number of characters. For example, the following expression is TRUE:
     "abcdefghij"="abc@"

The wildcard character must be used within the second operand (the string on the right side) in order to match any number of characters. The following expression is FALSE, because the @ is considered only as a one character in the first operand:

 "abc@"="abcdefghij"

The wildcard means “one or more characters or nothing”. The following expressions are TRUE:

 "abcdefghij"="abcdefghij@"
 "abcdefghij"="@abcdefghij"
 "abcdefghij"="abcd@efghij"
 "abcdefghij"="@abcdefghij@"
 "abcdefghij"="@abcde@fghij@"

On the other hand, whatever the case, a string comparison with two consecutive wildcards will always return FALSE. The following expression is FALSE:

 "abcdefghij"="abc@@fg"

When the comparison operator is or contains a < or > symbol, only comparison with a single wildcard located at the end of the operand is supported:

 "abcd"<="abc@" // Valid comparison
 "abcd"<="abc@ef"/Not a valid comparison/

Tip:If you want to execute comparisons or queries using @ as a character (and not as a wildcard), you have two options:

  • Use the Character code (At sign) instruction.
    Imagine, for example, that you want to know if a string ends with the @ character.
    - the following expression (if $vsValue is not empty) is always TRUE:
     ($vsValueLength($vsValue)≥="@")

- the following expression will be evaluated correctly:

 (Character code($vsValueLength($vsValue)≥)#64)

  • Use the "Consider @ as a wildcard only when at the beginning or end of text patterns" option which can be accessed using the Database Settings dialog box.
    This option lets you define how the @ character is interpreted when it is included in a character string. As such, it can influence how comparison operators are used in Query or Order By. For more information, refer to the 4D Design Reference manual.

 
PROPERTIES 

Product: 4D
Theme: Operators

 
SEE ALSO 

Bitwise Operators
Date Operators
Logical Operators
Numeric Operators
Operators
Picture Operators
Time Operators

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : Comparison Operators ( 4D v12.4)
Parent of : Comparison Operators ( 4D v13.5)