table find cells ...

Prev Next

Function Names

table find cells, table find cells seleted rows, table find cells in columns, table find cells selected rows in columns

Description

This function looks for cells using the right-hand comparison expression across all or selected columns and across all or selected rows. The return value will contain a set containing all coordinates in a 2-level set: { { row number, column number }, ... } .

Call as: procedure or 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-5

Parameters

No.TypeDescription
1.
input
string target table name

The target table must exist.

Opt. 2.
code
expression
:string
Expression to select rows

Applicable to table find cells selected rows and table find cells selected rows in columns:
Specify the conditions or rules to select the rows. 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 2. / 3.
input
table columns Header names and/or column numbers

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

2 / 3 / 4
input
string
set
values to compare

Provide one string or multiple strings in a set to compare with the table contents. wildcards are supported if the strings are of type softquoted string.

Opt. 3 / 4 / 5
input
string
set
options

One or multiple options may be applied.

Keyword Notes Description
above See 1 Coordinates of 1 row above will be returned. Note: Combination of 'above' and 'below' will cancel each other. But OK to combine with 'left' or 'right'.
below " Coordinates of 1 row below will be returned. Note: See above
left " Coordinates of 1 columne to the left will be returned. Note: Combination of 'left' and 'right' will cancel each other. But OK to combine with 'above' or 'below.
right " Coordinates of 1 columne to the right will be returned. See above
once See 2 Find at most 1 cell
once each " Find at most 1 cell for every comparison value
ignore case Search process ignores case, e.g. comparing 'ABC' with 'abc' yields true.
ignore blanks Search process ignores blanks, e.g. comparing 'can not' and 'cannot' yields true.

Notes:
1. Combination of multiple terms are allowed as usage of every turn displaces the position. Example: Combining 'above' and 'left' points to the cell 1 row above and 1 column to the left. Combining 'left' and 'right', as well as 'above' and 'below' cancel each other out. Mulitple use of a term is also allowed, e.g. 'left', 'left' indicates 2 fields to the left. No coordinates are returned if the final location lies beyond the first column, or on or above the header row.
2. 'once' and 'once each' cannot be combined.

Return value

TypeDescription
set Table coordinates (row, column) identified

A 2-level nested set containing rows and columns will be returned, e.g. { { row 1, column 1 }, { row 2, column 2 }, ... }. Empty set is returned in case of no matches.

Examples

table initialize( t,
               { { City,        State, Country },
                 { Tuscon,      AZ,    United States },
                 { Toronto,     ON,    Canada },
                 { Missisauga,  ON,    Canada },
                 { Zürich,      ZH,    Switzerland },
                 { Lake Zurich, MI,    United States } } );

table list(t);


c[] = table find cells( t, {} );
echo ("Nothing to look for: ", c[]);

c[] = table find cells( t, { canada, 'swit*' }, ignore case );
echo ("All countries except USA: ", c[]);

c[] = table find cells in columns( t, City, '*Z*rich*' );
echo ("All Cities somewhat sounding 'swiss', point on countries: ",c[]);

c[] = table find cells selected rows in columns( t, [Country]==Canada, State, ON, {once,left} );
echo ("1st Ontario match, point on city: ", c[]);
echo ("City is ", [t:c[]{0}{1},c[]{0}{0}] );

c[] = table find cells( t, Tuscon, left);
echo ("Empty set, as attempting to return coordinates beyond left side of table: ", c[]);

Output

    0 : City        | State | Country      
    1 : Tuscon      | AZ    | United States
    2 : Toronto     | ON    | Canada       
    3 : Missisauga  | ON    | Canada       
    4 : Zürich      | ZH    | Switzerland  
    5 : Lake Zurich | MI    | United States

Nothing to look for: {}
All countries except USA: {{2,2},{3,2},{4,2}}
All Cities somewhat sounding 'swiss', point on countries: {{4,0},{5,0}}
1st Ontario match, point on city: {{2,0}}
City is Toronto
Empty set, as attempting to return coordinates beyond left side of table: {}
Try it yourself: Open LIB_Function_table_find_cells.b4p in B4P_Examples.zip. Decompress before use.

See also

table replace cells
table read cells