在学习中遇到从列表框读取多维数组的问题,例如在textbox中有一个二维数组如下
那么如何将其写入数组array1(,)中呢。在这个问题中主要遇到的问题是将文本框中vb.net教程数组按行(vbcrlf)和空格(“ ”)分别split一次,在textbox的属性中有lines可以轻松的读取改行的信息。故创建如下ui及代码进行实验。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox2.Text = TextBox1.Lines(1)
TextBox3.Text = TextBox1.Lines.Count
Dim array1() As String
Dim array2(,) As String
Dim i, k, m As Integer
array1 = Split(Trim(TextBox1.Lines(0)), " ")
i = TextBox1.Lines.GetUpperBound(0)
For k = 0 To i
array1 = Split(Trim(TextBox1.Lines(k)), " ")
m = array1.GetUpperBound(0)
ReDim Preserve array2(i, m)
For j As Integer = 0 To m
array2(k, j) = array1(j)
Next
Next
Dim z, x As Integer
For z = 0 To array2.GetUpperBound(0)
For x = 0 To array2.GetUpperBound(1)
TextBox4.Text += array2(z, x) & " "
Next
TextBox4.Text += vbCrLf
Next
End Sub
End Class