diff --git a/src/ConsoleTables/ConsoleTable.cs b/src/ConsoleTables/ConsoleTable.cs index e2c2df6..4f9d89d 100644 --- a/src/ConsoleTables/ConsoleTable.cs +++ b/src/ConsoleTables/ConsoleTable.cs @@ -225,31 +225,32 @@ public string ToMinimalString() } public string ToStringAlternative() - { - var builder = new StringBuilder(); +{ + var builder = new StringBuilder(); - // find the longest formatted line - var columnHeaders = string.Format(Formats[0].TrimStart(), Columns.ToArray()); + // find the longest formatted line + var columnHeaders = string.Format(Formats[0].TrimStart(), Columns.ToArray()); - // add each row - var results = Rows.Select((row, i) => string.Format(Formats[i + 1].TrimStart(), row)).ToList(); + // add each row + var results = Rows.Select((row, i) => string.Format(Formats[i + 1].TrimStart(), row)).ToList(); - // create the divider - var divider = Regex.Replace(columnHeaders, @"[^|]", "-"); - var dividerPlus = divider.Replace("|", "+"); + // create the divider + var divider = Regex.Replace(columnHeaders, "[^| ]", "-"); + var dividerPlus = divider.Replace("|", "+"); - builder.AppendLine(dividerPlus); - builder.AppendLine(columnHeaders); + builder.AppendLine(dividerPlus); + builder.AppendLine(columnHeaders); - foreach (var row in results) - { - builder.AppendLine(dividerPlus); - builder.AppendLine(row); - } - builder.AppendLine(dividerPlus); + foreach (var row in results) + { + builder.AppendLine(dividerPlus); + builder.AppendLine(row); + } + builder.AppendLine(dividerPlus); + + return builder.ToString(); +} - return builder.ToString(); - } private string Format(List columnLengths, char delimiter = '|') {