table delete columns

Prev Next

Function Names

table delete columns

Description

This function deletes specified columns.

Deleting begins with the right-most column in the table, and not with the first (or last) column referenced. With this approach, the positions of the remaining columns further to the left will not shift.

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

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
  • No exceptions are asserted if header names are missing or column numbers are out of range.
  • Repeatedly specified header names and column numbers will be ignored

Opt. 3
input
numeral Number of columns to delete

By default, the specified column will be deleted.
If 0 is specified, then nothing will be deleted.
If a value greater than 1 is specified, then additional columns to the right will be deleted, too.
-1 deletes all remaining columns to the end of the table (maximum table width)
-2 (-3, ...) deletes all remaining columns except the last (2nd last, ...) column. Strongly recommended to use negative number only with one one header name or column number.

Default value: 1

Return value

TypeDescription
numeral Number of columns deleted

Exceptions

Table not found
Header name not found

Examples

       echo("Delete 3 column pairs");
       table initialize ( table, { { 'Col A' .. 'Col K' }, { 'Val A' .. 'Val K' } } );

       // Deletes 6 columns: H & I, C & D, and B & E. Remaining; A, F, G, J and K
       echo( "# columns deleted: ", table delete columns ( table, {7, Col B, Col C}, 2 ) );

       table delete columns ( table, Col A, 0 );  // Nothing happens here (0 columns deleted)

       table list( table );

       echo("Delete all columns between D and K");
       table initialize ( table, { { 'Col A' .. 'Col K' }, { 'Val A' .. 'Val K' } } );

       table delete columns ( table, Col F, -2 );

       table list( table );

Output

Delete 3 column pairs
# columns deleted: 6
    0 : Col A | Col F | Col G | Col J | Col K
    1 : Val A | Val F | Val G | Val J | Val K

Delete all columns between D and K
    0 : Col A | Col B | Col C | Col D | Col E | Col K
    1 : Val A | Val B | Val C | Val D | Val E | Val K

Try it yourself: Open LIB_Function_table_delete_columns.b4p in B4P_Examples.zip. Decompress before use.

See also

table delete remaining columns