table correct headers ...

Prev Next

Function Names

table correct headers, table correct headers ignore case

Description

This function helps to correct or align column header names and is particularly useful for tables originating from different sources where wordings or spellings of header names show slight differences and you want to harmonize them easily be correcting them. The functions described here differ from table rename headers() in the 2nd parameter: Instead of specifying specific columns, comparison patterns are used to check all headers from left to right until the first match is found.

The function name table correct headers ignore case ignore case sensitivity while comparing headers with comparison patterns provided.
No exceptions are asserted if a comparison of a matching pattern with the table headers results in no matches.

Note: This function supports wildcard symbols if the strings used for comparison patterns are softquoted, i.e. using single quotation marks.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

3

Parameters

No.TypeDescription
1
input
string Name of existing table

2
input
set or string Existing header name(s) or column number(s)

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.

3
input
set or string New header name(s)

List the new header names corresponding to the existing ones specified in the previous function parameter.
Use string to specify a single table, or a set or softquoted string (single quotation marks) with names separated by comma to specify multiple columns.

Return value

TypeDescription
numeral Number of corrections accomplished

Exceptions

Table not found
number of comparison pattersn and new headers is inconsistent

Examples

       table initialize ( table, { { first  name, Lastname, Phone No, Age }, { Jim, Archer, "1-212-555-1212", 28 } } );

       count[] = table correct headers ignore case( table, {'Last*name', 'First*name', 'Family*' },
               { Last Name, First Name, Last Name } );

       table list ( table );
       echo;
       echo("Number of headers corrected: ", count[]);

Output

    0 : First Name | Last Name | Phone No       | Age
    1 : Jim        | Archer    | 1-212-555-1212 | 28


Number of headers corrected: 2
Try it yourself: Open LIB_Function_table_correct_headers.b4p in B4P_Examples.zip. Decompress before use.

See also

table rename existing headers