Render an aligned plain-text table from string rows
C#
using System;
using System.Collections.Generic;
using System.Linq;
static string RenderTable(IReadOnlyList<string[]> table)
{
int cols = table.Max(row => row.Length);
int[] widths = Enumerable.Range(0, cols)
.Select(c => table.Max(row => c < row.Length ? row[c].Length : 0)).ToArray();
var lines = table.Select(row => string.Join(" ", row.Select((cell, c) => cell.PadRight(widths[c])))).ToList();
lines.Insert(1, new string('-', widths.Sum() + 2 * (widths.Length - 1)));
return string.Join(Environment.NewLine, lines);
}