在 Visual Basic 中正确格式化文本 table

Properly formatting a text table in Visual Basic

目前,我正在尝试用 Visual Basic 编写一个程序,以根据一定数量的结果输出基于 table 的文本。

我正在尝试合并类似下面的 C++ 代码来正确格式化 table 但无法确定在 Visual Basic 中使用什么代码来实现类似的效果。 (我知道 coutendl 是 C++ 特有的,但我希望存在 VB 的替代方案)

cout << endl << "Month#      Interest Amount     Monthly Amount     New Amount" << endl;

int counter = 1;
while (counter <= length * 12) {
    cout << right << setw(6) << counter; // Month Counter
}

不用给出太多的代码也不会把它弄得一团糟,这就是我所拥有的。

    Dim strOutput As String
    Dim strParticipantList As String = ""

    Dim outFile As IO.StreamWriter

    strOutput = Trim(eventName & " Final Results") & vbNewLine + vbNewLine + _
                "Total Number of Participants: " + TotalParticipants & vbNewLine

    For Each storage As StopwatchStorage In _storage
        strParticipantList &= storage.ParticipantOrder.Text
    Next

我的想法是,我将循环遍历存储中的每个项目,并将行的格式正确设置为字符串,格式类似于 C++ 代码中所述的 cout

Using outFile As New IO.StreamWriter("File Path Here")
    outFile.WriteLine("{0} Final Results", eventName)
    outFile.WriteLine()
    outFile.WriteLine("Total Number of Participants: {0}", TotalParticipants)
    outFile.WriteLine()

    'Using C++ example with some made-up variable names to show how this can work
    outFile.WriteLine("Month#      Interest Amount     Monthly Amount     New Amount")
    For Each storage As StopwatchStorage In _storage
        outFile.WriteLine("{0,-6} {1,-20} {2,-18} {3,-14}", _
            storage.Month, storage.Interest, storage.MonthlyTotal, storage.NewTotal)
    Next
End Using

{x} 占位符标记后面参数中的索引以供替换。 {m,n} 占位符使用逗号后的部分来设置项目的宽度。对于那么多字符,正数左对齐,负数右对齐。这是 documentation for how it works.