xHarbour Reference Documentation > Operator Reference |
Searches a value in another value.
<cSubString> IN <cString> <xValue> IN <aArray> <xKey> IN <hHash>
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.
See also: | $, AScan(), HAS, LIKE, HScan() |
Category: | Character operators , Comparison operators , Operators , xHarbour extensions |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com