xHarbour Reference Documentation > Function Reference |
Searches a value in an array beginning with the first element.
Ascan( <aArray> , ; <xbSearch>, ; [<nStart>], ; [<nCount>], ; [<lExact>], ; [<lASCII>] ) --> nElement
AScan() returns the numeric ordinal position of the array element that contains the searched value. When no match is found, the return value is 0.
The array function AScan() traverses the array <aArray> for the value specified with <xbSearch>. If <xbSearch> is not a code block, AScan() compares the values of each array element for being equal with the searched value. If this comparison yields .T. (true), the function stops searching and returns the numeric position of the array element containing the searched value.
If a code block is passed for <xbSearch>, it is evaluated and receives as parameter the value of the current array element. The code block must contain a comparison rule that yields a logical value. AScan() considers the value as being found when the codeblock returns .T. (true). Otherwise the function proceeds with the next array element.
Note: use function RAscan() to search an array beginning with the last element.
See also: | AEval(), Asc(), ASort(), ATail(), Eval(), IN, RAscan(), SET EXACT |
Category: | Array functions |
Source: | vm\arrayshb.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates simple and complex searching in arrays. PROCEDURE Main() LOCAL aArray := { "A", 1, Date(), NIL, .F. } // one dimensional array ? AScan( aArray, 1 ) // result: 2 ? AScan( aArray, .F. ) // result: 5 ? AScan( aArray, {|x| Valtype(x)=="D" } ) // result: 3 // two dimensional array aArray := Directory( "*.prg" ) ? AScan( aArray, {|a| Upper(a[1]) == "TEST.PRG" } ) // result: 28 RETURN
http://www.xHarbour.com