table find row

Prev Next

Function Names

table find row

Description

This function compares a table by checking the the data in the columns provided with the values provided in the 3rd function parameter. The comparison is carried in the same way as if the table cells are compared with the values using the equal to sign =. Depending on the table configiuration (see table configure(), the values retrieved from the table may be converted automatically, which is in the case for reading numerals in the default case.

Wildcards are supported in the matching patterns if the comparison values are provided as softquoted strings and contain wildcard symbols and strings are compared. Mismatching types return false, e.g numeric 1 compared with string '1'.

If a row is found, then the row number will be returned. Otherwise, this function returns -1.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

3-4

Parameters

No.TypeDescription
1.
input
string Name of existing table

2
input
table columns Header names and/or column numbers to compare

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Any number of header names and column numbers may be specified

3
input
set or string Comparison values or patterns

The nummber of elements must match with the number of headers (2nd function parameter). Specify the comparison patterns.

  • Unquoted or quoted strings as elements in set: True comparison of contents without wildcards, e.g. { Name, "Street" }
  • Softquoted strings in set: You can use wildcard symbols, e.g. { '* Name', 'City,Town' }
  • One quoted string specifies just one item to compare, e.g. "Last Name"
  • One softquoted string converts the contents into a set os strings.

Opt. 4
input
numeral Starting row number

The search begins at the specified row number. Negative indexing is supported.

Default value: 1 (1st data row)

Return value

TypeDescription
numeral Row number with match found

-1 is returned if no match has been found.

Examples

       table load( c, "Examples\Cities.csv");

       row[] = table find row( c, { City, Country }, { Los Angeles, USA } );
       echo("Los Angeles is found in row: ", row[] );

       row[] = table find row( c, { City, Country }, { Los Angeles, CAN } );
       echo("Los Angeles is not found, returning : ", row[] );

       row[] = table find row( c, { City, Country }, { Los Angeles, 'U*' } );
       echo("Los angeles is found in row: ", row[] );

       row[] = table find row( c, { City, Country }, { Los Angeles, "U*" } );
       echo("Los Angeles is not found, returning : ", row[] );

       row[] = table find row( c, { Inhabitants, Country }, { 404000, '*' } );
       echo("Zürich found in row: ", row[] );

Output

Los Angeles is found in row: 9
Los Angeles is not found, returning : -1
Los angeles is found in row: 9
Los Angeles is not found, returning : 9
Zürich found in row: 12
Try it yourself: Open LIB_Function_table_find_row.b4p in B4P_Examples.zip. Decompress before use.

See also

table search row