xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

<> != #

Not equal operator (binary): compares two values for inequality.

Syntax

<Expression1> <> <Expresson2>
<Expression1> != <Expresson2>
<Expression1> # <Expresson2>

Arguments

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

Description

The "not equal" operator compares two values of the same data type or NIL. It returns .T. (true) when the left operand has not the same value as the right operand, otherwise the return value is .F. (false).

Only the simple data types Character, Date, Logic, Memo, Numeric and the value NIL can be compared. The complex data types Array, Code block and Object cannot be used with the "not 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 smaller than 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 "not 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:$, <, <=, = (comparison), ==, >, >=, SET EXACT
Category: Comparison operators , Operators
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates the result of the "<>" operator.

   PROCEDURE Main

      SET EXACT ON
      ? "ABC"   <> "ABCDE"             // result: .T.
      ? "ABCDE" <> "ABC"               // result: .T.

      ? "ABC"   <> ""                  // result: .T.
      ? ""      <> "ABC"               // result: .T.

      SET EXACT OFF
      ? "ABC"   <> "ABCDE"             // result: .T.
      ? "ABCDE" <> "ABC"               // result: .F.

      ? "ABC"   <> ""                  // result: .F.
      ? ""      <> "ABC"               // result: .T.

      ? CToD("12/28/2005") <> CToD("12/31/2005")
                                       // result: .T.

      ? NIL <> NIL                     // result: .F.
      ? 2 <> 1                         // result: .T.
  RETURN

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