table search header row

Prev Next

Function Names

table search header row

Description

This function is particularly useful for imported tables where the headers are not necessarily be located in the top row but somewhere else. To make things worse, the headers of the imported tables may be located in different rows. This function searches for the header row and returns the row number. In contrast to table lift header row(), the table remains untouched.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

2, 3

Parameters

No.TypeDescription
1.
input
string Name of existing table

2
input
table columns Existing columns considered part of headers

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

Opt. 3
input
string Check header option

With this option, you can make the search more restrictive, so wrong arrangements located further up in the table will not be detected first. Checking option 1 affecting the table headers. Only one option can be chosen. See separate table on next page for more details.

Hint: The following terms behave similarly as in the function table check headers in order to qualify for matches. For example, the option "full match" expects that the header row contains all specified headers and not more in oder to consider them found. Otherwise, searching continues in the rows below until the criteria are met.

must exist The specified header names must exist
Specifeid column numbers must be within 0..n-1 or -n..-1.
unique Like must exist, but also checks that the specified column headers are unique in the table, i.e. they exist only once.
full match Like unique, however the table must not contain more (or less) headers than those specified to check. The ordering does not matter. It's like tolerating full number of white pins after a guess in the Master Mind game.
sequence Like unique, but listed parameters are in left-to-right sequence. The checked headers do not need to be adjacent.
strict sequence Like sequence but all headers must be adjacent, being next to each other from left to right
identical Combination of full match and strict sequence. The headers provided and table headers must be identical: Same header names in the same sequence. This corresponds to full number of black pins in the Master Mind game.

Default value: must exist

Return value

TypeDescription
numeral Row number where header row has been found

-1 is returned if no header row has been found

Examples

  table initialize( 2 tables,
  { { Created by,  Nick, Miller, "", Last Update, "31.12.2019" },
    { Tennis, Players, "", "", Squash, Players },
    {     Still a, "", "", "", Last Name, First Name, City },
    {     Draft, "", "", "", Weber, Abel, 'Wilkes-Barre' },
    { First Name, Last Name, City, and, Tanner, Berta, San Monica },
    { Jane, Dominique, The Bronx, "", Miller, Dominique, Trenton },
    { Jasmine, Nelsson, Francfort, "", Quinn, Alex, Denver },
    { Dominique, Miller, Trenton, "", Jansen, Patricia, Albany } } );


  echo("Original table:");
  table list( 2 tables );

  a[] = table search header row( 2 tables, {First Name, Last Name, City} ); // 'must exist' is default
  // Finds header row in the right table (headers are on row 2)
  b[] = table search header row( 2 tables, {First Name, Last Name, City}, sequence ); // 'must exist' is default
  // Finds header row in the left table (headers are on row 4)

  c[] = table search header row( 2 tables, {First Name, Last Name, Town} ); // Not found, returns -1
  // Header row will not be found.

  echo(a[], " / ", b[], " / ", c[] );

Output

Original table:
    0 : Created by | Nick      | Miller    |     | Last Update | 31.12.2019 |             
    1 : Tennis     | Players   |           |     | Squash      | Players    |             
    2 : Still a    |           |           |     | Last Name   | First Name | City        
    3 : Draft      |           |           |     | Weber       | Abel       | Wilkes-Barre
    4 : First Name | Last Name | City      | and | Tanner      | Berta      | San Monica  
    5 : Jane       | Dominique | The Bronx |     | Miller      | Dominique  | Trenton     
    6 : Jasmine    | Nelsson   | Francfort |     | Quinn       | Alex       | Denver      
    7 : Dominique  | Miller    | Trenton   |     | Jansen      | Patricia   | Albany      

2 / 4 / -1
Try it yourself: Open LIB_Function_table_search_header_row.b4p in B4P_Examples.zip. Decompress before use.

See also

table lift header row