xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

= (comparison)

Equal operator (binary): compares two values for equality.

Syntax

<Expression1> = <Expression2>

Arguments

<Expression>
The values of <Expression1> and <Expression2> must have the same data type or can be NIL, and are compared.

Description

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 typeComparison
CharacterThe comparison is based on the ASCII value of the characters.
DateThe comparison is based on the underlying date value.
LogicalFalse (.F.) is not equal to true (.T.).
MemoSame as Character data type.
NumericComparison is based on the value of the numerics.
NILNIL 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.

Info

See also:$, <, <=, <> != #, ==, >, >=, SET EXACT
Category: Comparison operators , Operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe