多行文本框到2d数组

时间:2012-11-19 22:28:16

标签: arrays vb.net .net-4.0

我如何将以下输入插入到2d数组中,或者如果需要将相同的效果插入到不同类型的数组中。

  abcd
  efgh
  ijkl

当我点击一个按钮时,我的阵列向右或向左旋转90度(如果选择)我已经考虑了大约一个小时我尝试了一些东西但是我在VB.net上是全新的< / p>

使用数字代替的例子:

1 2 3
4 5 6
7 8 9

旋转:

7 4 1
8 5 2
9 6 3

等等

1 个答案:

答案 0 :(得分:0)

这可能会让你开始你想要动态设置“行”和“列”的上限。这会将其输出到文本框,但将变量分配给新数组会很容易。

Dim arr(3, 3) As String

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim i As Integer = 1
    For row As Integer = 0 To 2
        For col As Integer = 0 To 2
            arr(row, col) = i
            i += 1
        Next
    Next
End Sub

Public Sub showStraight()
    TextBox1.Text = ""
    For row As Integer = 0 To 2
        Dim line As String = ""
        For col As Integer = 0 To 2
            line += arr(row, col)
        Next
        TextBox1.Text += line & vbNewLine
        line = ""
    Next
End Sub    Public Sub showRotated()
    TextBox1.Text = ""
    For col As Integer = 0 To 2
        Dim line As String = ""
        For row As Integer = 2 To 0 Step -1
            line += arr(row, col)
        Next
        TextBox1.Text += line & vbNewLine
        line = ""
    Next
End Sub