Visual Studio: 如何在 for 循环中的文本前放置空格

Visual Studio: How to put spaces before the text in a for loop

我需要你的帮助来解决这个问题。我想要做的是在给定的坐标或空间内创建一个矩形。到目前为止,这是我的代码,我在这里缺少什么?请参阅下面的示例输入和输出。

Dim d As String = ""
Dim s As String = ""
Dim counter As Integer = 0

For i = 1 To y
    s = s & vbNewLine
Next

For row = 1 To height
    For col = 1 To width
         If x <> 0 Then



         Else
             d = d & "X "
         End If
        Next
        d = d & vbNewLine
    Next
outputTBX.Text = s & d

这是我的示例输入,但是,如果您查看示例输出,X 之前应该有 2 个空格。提前致谢!

宽度:4

身高:4

X轴:2

Y轴:2

请看下面。我认为您错过了添加空格的 col offset 循环。

Sub Main
    DrawRectangle(4,4,2,2)
End Sub

Sub DrawRectangle(ByVal height As Integer, ByVal width As Integer, ByVal x As Integer, ByVal y As Integer) 

Dim d As String = ""
Dim s As String = ""
Dim counter As Integer = 0

' row offset
For i = 1 To y
    s = s & Environment.NewLine 
Next

' row loop
For row = 1 To height
    'col offset
    For i = 1 To x
        d = d & " "
    Next
    'col loop
    For col = 1 To width
         d = d & "X"
    Next
    d = d & Environment.NewLine 
Next

' uncomment outputTBX and comment console for your work
'outputTBX.Text = s & d
Console.WriteLine(s & d)

End Sub