table delete blank rows

Prev Next

Function Names

table delete blank rows

Description

This function deletes all blank rows from all listed tables, or reduces the number of consecutive blank rows to a specified number.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

1 - 4

Parameters

No.TypeDescription
1.
input
string Name of existing table

Opt. 2.
input
numeral Number of consecutive rows to keep

If 1 (or 2, 3, ...) is specifed, then number of consecutive blank rows will be reduced to (or 2, 3, ...).

Default value: 0
Opt. 3.
input
string Blank criterion

One of following:

entirely empty row Delete if row contain 0 columns
empty row Delete if row contains 0 or 1 empty column
empty fields Delete if row contains any number of empty fields (nothing inside, not even a white space)
blank fields Delete if row contains any number of fields which are either empty or containing white spaces (no visible characters)
not blank begin Delete if not blank, but row above meets blank fields criteria
not blank middle Delete if not blank, rows above and below are not blank, too
not blank end Delete if not blank, but row below meets blank fields criteria
not blank lone Delete if row is not blank, but row above and below meet blank fields criteria.
not blank Delete if row is not blank (contains visible characters), regardless if at top, middle or end of block of non-blank rows

Default value: blank fields
Opt 4
input
table columns Columns to check

Specify the columns which shall be checked if they are blank and ignore the contents in the remaining 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

Default value: all columns

Return value

TypeDescription
numeral Number of rows deleted

Examples

  table initialize( t,
      { {  Last Name,    First Name,    Favorite Sports },
        {  Adams,        Andy,          American Football },
        {  "  ",         "",            Baseball },
        { },
        {  "" },
        {  " " },
        {  Mayer,        Mick,          Tennis },
        {  Tanner,       Tina,          Wrestling } } );

echo ("Original table:");
table list(t);

echo ("Demonstrate deleting all rows:");
table copy table        ( t, u );
table delete blank rows ( u );
table list              ( u );

echo (new line, "Demonstrate deleting all rows without names");
table copy table        ( t, u );
table delete blank rows ( u, 0, blank fields, {First Name, Last Name} );
table list              ( u );

echo (new line, "Demonstrate deleting empty rows (0 columns) -> only 1 row removed");
table copy table        ( t, u );
table delete blank rows ( u, 0, entirely empty row );
table list              ( u );

echo (new line, "Reduce # blank rows to 1:");
table copy table        ( t, u );
table delete blank rows ( u, 1 );
table list              ( u );

Output

Original table:
    0 : Last Name | First Name | Favorite Sports  
    1 : Adams     | Andy       | American Football
    2 :           |            | Baseball         
    3 :           |            |                  
    4 :           |            |                  
    5 :           |            |                  
    6 : Mayer     | Mick       | Tennis           
    7 : Tanner    | Tina       | Wrestling        

Demonstrate deleting all rows:
    0 : Last Name | First Name | Favorite Sports  
    1 : Adams     | Andy       | American Football
    2 :           |            | Baseball         
    3 : Mayer     | Mick       | Tennis           
    4 : Tanner    | Tina       | Wrestling        


Demonstrate deleting all rows without names
    0 : Last Name | First Name | Favorite Sports  
    1 : Adams     | Andy       | American Football
    2 : Mayer     | Mick       | Tennis           
    3 : Tanner    | Tina       | Wrestling        


Demonstrate deleting empty rows (0 columns) -> only 1 row removed
    0 : Last Name | First Name | Favorite Sports  
    1 : Adams     | Andy       | American Football
    2 :           |            | Baseball         
    3 :           |            |                  
    4 :           |            |                  
    5 : Mayer     | Mick       | Tennis           
    6 : Tanner    | Tina       | Wrestling        


Reduce # blank rows to 1:
    0 : Last Name | First Name | Favorite Sports  
    1 : Adams     | Andy       | American Football
    2 :           |            | Baseball         
    3 :           |            |                  
    4 : Mayer     | Mick       | Tennis           
    5 : Tanner    | Tina       | Wrestling        

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

See also

table delete selected rows
table check row