Zend Certified Engineer

phpguru.org

Quality PHP, Javascript and C# code

Firefox 3.5

Console Table class

A class for building console/ASCII based tables (like the ones the MySQL client produces). Has Append/Prepend/Insert methods and supports table headers and footers. Automatically handles setting the correct widths for columns.

Example

ConsoleTable table = new ConsoleTable();

table.AppendRow(new string[] {"foo", "bar", "jello"});
table.AppendRow(new string[] {"foo", "bar", "jello"});
table.AppendRow(new string[] {"foo", "bar", "jello"});
table.AppendRow(new string[] {"foo", "bar", "jello"});

table.SetHeaders(new string[] {"First Column", "Second Column", "Third Column"});
table.SetFooters(new string[] {"Yabba"});

table.InsertRow(new string[] {"", "ferfr", "frf        r"}, 7);
table.PrependRow(new string[] {});

System.Console.Write(table.ToString());

Produces...

+--------------+---------------+--------------+
| First Column | Second Column | Third Column |
+--------------+---------------+--------------+
|              |               |              |
| foo          | bar           | jello        |
| foo          | bar           | jello        |
| foo          | bar           | jello        |
| foo          | bar           | jello        |
|              |               |              |
|              |               |              |
|              |               |              |
|              | ferfr         | frf        r |
+--------------+---------------+--------------+
| Yabba        |               |              |
+--------------+---------------+--------------+

Download now

Counter