table search row

Prev Next

Function Names

table search row

Description

This function works through all table rows until the expression specfified returns true. The row number is returned.

Call as: function

Restrictions

Indirect parameter passing is disabled
This function provides a table context for partial table specifications with table name and row number for selected function parameters

Parameter count

2-3

Parameters

No.TypeDescription
1.
input
string Name of existing table

2.
code
expression
:string
Expression to select rows

Specify the conditions or rules to select the row. See expressions to select rows.
The table context for partial table specifications is available for referencing just the columns easily. Example: [Year]>=2022.
Attention: Comparison operators = and <> (instead of == and !=) may hijack the next function parameters for its own use as additional comparison operands, e.g. a[]=1,3,5. As long this comparison is not made in the last function parameter, then put parentheses around them, e.g. ... , (a[]=1,3,5), ....

Opt. 3.
input
numeral Starting row number

Note: Negative row numbers count from last row upwards

Return value

TypeDescription
numeral Row number with match found

-1 is returned if no match has been found.

Examples

       table initialize ( table 1,
       { { Animal, leg count }, { Worm,  0}, { Bird, 2 }, { Dog, 4 }, { Fly, 6 }, { Tick, 8 } } );

       r[1] = table search row( table 1, [Animal]='*i*' );
       r[2] = table search row( table 1, ([Animal]='*i*'), r[1]+1 );
       r[3] = table search row( table 1, ([Animal]='*i*'), r[2]+1 );

       // Note that comparison is in parentheses, so the next function parameter is not regarded
       // as part of a comparison expression.

       echo( "1st match: ", r[1] );
       echo( "2nd match: ", r[2] );
       echo( "3rd match: ", r[3] ); // -1 because only 2 words containing 'i' exist.

Output

1st match: 2
2nd match: 5
3rd match: -1
Try it yourself: Open LIB_Function_table_search_row.b4p in B4P_Examples.zip. Decompress before use.

See also

table read column selected rows
table find row
table selected columns