xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

IN

Searches a value in another value.

Syntax

<cSubString> IN <cString>
<xValue>     IN <aArray>
<xKey>       IN <hHash>

Arguments

<cSubString>
<cSubString> is a character or other value that is searched for in <cString>.
<aArray>
<aArray> is an array with random values.
<xKey>
<xKey> is a value to search in a hash.
<hHash>
<hHash> is a hash value whose keys are searched for <xKey>.

Description

The IN operator searches the left operand in the right operand and returns .T. (true) if the value of the left operand is contained in the value of the right operand, otherwise .F. (false) is returned.

Substring search

When both operands are character strings, the IN operator performs a case-sensitive substring search and returns .T. (true) if <cSubString> is found in <cString>, otherwise .F. (false). This is the same search as with the $ operator, but IN is much faster.

Array search

If the right operand is an array, the IN operator scans the elements of <aArray> in the first dimension and returns .T. (true) if an element contains the value of the left operand. <xValue> may be of any data type.

Hash key search

If the right operand is a hash, the IN operator scans the keys of <hHash> (which is similar to the first column of a two column array) and returns .T. (true) if the hash has the key <xKey>. <xKey> may be of any data type.

Info

See also:$, AScan(), HAS, LIKE, HScan()
Category: Character operators , Comparison operators , Operators , xHarbour extensions
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates results of the IN operator with values
// of different data types.

   PROCEDURE Main
      LOCAL cString := "xHarbour"
      LOCAL hHash   := { "A" => Date(), 1 => "B" }
      LOCAL aSub    := { 1, 2 }
      LOCAL aArray  := { 1, Date(), aSub }

      ? "A"   IN cString               // result: .F.
      ? "arb" IN cString               // result: .T.

      ?  "A"  IN hHash                 // result: .T.
      ?  "B"  IN hHash                 // result: .F.
      ?   1   IN hHash                 // result: .T.

      ? "A"    IN aArray               // result: .F.
      ? Date() IN aArray               // result: .T.
      ? aSub   IN aArray               // result: .T.
   RETURN

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