【发布时间】:2015-10-01 13:04:02
【问题描述】:
我正在使用 `Console.WriteLine()' 将随机“卡片”打印到控制台。
我正在尝试用两部分打印一行。该行的第一部分显示了您绘制的卡片的长名称。第二部分显示西装图标和号码:
有没有办法以更整洁/统一的方式显示该行的第二部分?像这样的东西:
出现问题是因为我的线的第一部分会根据面值和花色改变大小。这是我用来打印卡片的代码:
Console.Write("Your card is a{0} " & textValue & " of " & suit, IIf(textValue = "Ace", "n", ""))
Console.Write(" " & suitIcon & " " & textValue)
Console.WriteLine()
我还尝试了以下方法:
Console.Write("Your card is a{0} " & textValue & " of " & suit, IIf(textValue = "Ace", "n", ""))
Dim string2 As String = (suitIcon & " " & textValue)
Dim padAmount As Integer = 50 - (suit.Length + textValue.Length)
Console.Write(string2.PadLeft(padAmount, " "c))
Console.WriteLine()
【问题讨论】:
-
如果将字符串填充到 X 个字符的长度会怎样?
-
@Capellan 感谢您的回复。我已经尝试使用填充更新了这个问题。它似乎不像我想要的那样工作。
标签: vb.net format command-line-interface multiple-columns console.writeline