xHarbour Reference Documentation > Operator Reference |
Equal operator (binary): compares two values for equality.
<Expression1> = <Expression2>
The "equal" operator compares two values of the same data type or NIL. It returns .T. (true) when the left operand has the same value as the right operand, otherwise the return value is .F. (false).
Only the simple data types Character, Data, Logic, Memo, Numeric and the value NIL can be compared. The complex data types Array, Code block, Hash and Object cannot be used with the "equal" operator. This is only possible with the "exact equal" operator.
Comparison rules
Data type | Comparison |
---|---|
Character | The comparison is based on the ASCII value of the characters. |
Date | The comparison is based on the underlying date value. |
Logical | False (.F.) is not equal to true (.T.). |
Memo | Same as Character data type. |
Numeric | Comparison is based on the value of the numerics. |
NIL | NIL is equal to NIL and not equal to any other data type. |
SET EXACT
For character comparisons, the "equal" operator takes the SET EXACT setting into account. With SET EXACT OFF, characters are compared up to the length of the right operand. With SET EXACT ON, characters are compared up to the length of the left operand and trailing blank spaces are ignored.
See also: | $, <, <=, <> != #, ==, >, >=, SET EXACT |
Category: | Comparison operators , Operators |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example shows results of the = operator. PROCEDURE Main SET EXACT ON ? "ABC" = "ABC " // result: .T. ? "ABC " = "ABC" // result: .T. ? "" = "ABC" // result: .F. ? "ABC" = "" // result: .F. ? "ABC" = "ABCDE" // result: .F. ? "ABCDE" = "ABC" // result: .F. SET EXACT OFF ? "ABC" = "ABC " // result: .F. ? "ABC " = "ABC" // result: .T. ? "" = "ABC" // result: .F. ? "ABC" = "" // result: .T. ? "ABC" = "ABCDE" // result: .F. ? "ABCDE" = "ABC" // result: .T. ? CToD("12/28/2005") = CToD("12/31/2005") // result: .F. ? .T. = .F. // result: .F. ? NIL = NIL // result: .T. ? 2 = 1 // result: .F. RETURN
http://www.xHarbour.com