table resolve headers

Prev Next

Function Names

table expand headers

Description

This function resolves specified table headers headers in the following way and returns the result in the return value.

  • Ranges, e.g. {Street address, '..', Country}, are rolled out, e.g. resulting in {Street address, Town, Region, Country}.
  • Prefixes like '<' and '>' are also resolved by referencing to the neighboring columns directly.
  • Asterisks '*' translate to all column headers listed indiviudally.
  • Shifted table column specifications are also resolved, e.g. '>City' refers to the next column to the right of 'City'.

This function provides three different options to resolve header specifications:

  • The header names, as specified in row 0 are returned.
    Note: This option is risky because of ambiguities with tables containing multiple identical header names and/or multiple blank headers.
  • Like above, but column numbers are provided for repeated headers and blank headers, allowing to access every header directly.
  • Column numbers are provided. Works similar like table column numbers().

Call as: 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 Columns

Specific rules apply for this function:

  • Any number of header names and column numbers may be specified
  • Specify '*' (asterisk as softquoted string) alone to select all columns

See table columns as function parameters for general ruling for this parameter.

3
input
string Option

Following options are available:

  • use names: Output contains header names only.
  • prefer names: Output contains header names, and in case of ambiguities and blank headers: column numbers
  • use numbers: Output contains column numers

See table columns as function parameters for general ruling for this parameter.

Default value: prefer names

Return value

TypeDescription
set Expanded list of headers

Individual header names, and/or column numbers.

Exceptions

Table not found
Columns not found

Examples

table initialize( t, { { Name, Street, '', '', Town, Postal Code, Town, Region, Country, Continent, Phone, 'E-Mail' } } );

echo( "Table headers: ", [t:..,0], new line);

echo( "Input: { Name, '', 3, Town, '>Town', '..', Continent, 1 }");

echo( "   ", table resolve headers( t, { Name, '', 3, Town, '>Town', '..', Continent, 1 } ) );
echo( "   ", table resolve headers( t, { Name, '', 3, Town, '>Town', '..', Continent, 1 }, prefer names ) ); // Same as above
echo( "   ", table resolve headers( t, { Name, '', 3, Town, '>Town', '..', Continent, 1 }, use names    ) );
echo( "   ", table resolve headers( t, { Name, '', 3, Town, '>Town', '..', Continent, 1 }, use numbers  ) );

echo(new line, "And when all columns are selected:");

echo( "   ", table resolve headers( t, '*',  prefer names ) );
echo( "   ", table resolve headers( t, '..', prefer names ) ); // Same as above
echo( "   ", table resolve headers( t, '*',  use names    ) );
echo( "   ", table resolve headers( t, '*',  use numbers  ) );

Output

Table headers: {'Name','Street','','','Town','Postal Code','Town','Region','Country','Continent','Phone','E-Mail'}

Input: { Name, '', 3, Town, '>Town', '..', Continent, 1 }
   {'Name',2,3,'Town','Postal Code',6,'Region','Country','Continent','Street'}
   {'Name',2,3,'Town','Postal Code',6,'Region','Country','Continent','Street'}
   {'Name','','','Town','Postal Code','Town','Region','Country','Continent','Street'}
   {0,2,3,4,5,6,7,8,9,1}

And when all columns are selected:
   {'Name','Street',2,3,'Town','Postal Code',6,'Region','Country','Continent','Phone','E-Mail'}
   {'Name','Street',2,3,'Town','Postal Code',6,'Region','Country','Continent','Phone','E-Mail'}
   {'Name','Street','','','Town','Postal Code','Town','Region','Country','Continent','Phone','E-Mail'}
   {0,1,2,3,4,5,6,7,8,9,10,11}
Try it yourself: Open LIB_Function_table_expand_headers.b4p in B4P_Examples.zip. Decompress before use.

See also

table column numbers
table check headers