Skip to content

Commit

Permalink
Updated ToStringAlternative() ConsoleTable.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmander authored Sep 29, 2023
1 parent c0528c9 commit 8762e7b
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/ConsoleTables/ConsoleTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> columnLengths, char delimiter = '|')
{
Expand Down

0 comments on commit 8762e7b

Please sign in to comment.