xHarbour Reference Documentation > Function Reference |
Searches a value in a hash.
HScan( <hHash> , ; <xValue> , ; [<nStart>], ; [<nCount>], ; [<lExact>], ; [<lASCII>] ) --> nPos
The function returns the numeric ordinal position of <xValue> in <hHash>, or zero when the value is not found.
The function is used to search a value in a hash. It accepts either the value to search, or a code block that specifies the search condition.
If <xValue> is a code block, it receives three parameters: the key, the value and the numeric ordinal position of the current key/value pair in <hHash>. The code block must return a logical value. When it returns .T. (true), the search condition is satisfied and HScan() returns the ordinal position of the current item in <hHash>.
See also: | Hash(), HEval(), HGetPos(), HGetValueAt() |
Category: | Hash functions , xHarbour extensions |
Source: | vm\hash.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates various results of HScan() // using search values and search conditions (code blocks) PROCEDURE Main LOCAL hHash := {=>} hHash[ "a" ] := "Hello" hHash[ "b" ] := { 1, 2 } hHash[ "c" ] := Date() hHash[ "d" ] := 1 hHash[ "e" ] := { 4, 5 } ? HScan( hHash, "Hello" ) // result: 1 ? HScan( hHash, 1 ) // result: 4 ? HScan( hHash, Date() ) // result: 3 ? HScan( hHash, {|k,v,i| Valtype(v)=="A" .AND. v[1] == 1} ) // result: 2 ? HScan( hHash, {|k,v,i| Valtype(v)=="A" .AND. v[1] == 4} ) // result: 5 RETURN
http://www.xHarbour.com