数组数据类型问题

问题描述:

我想按字符顺序从文本框中读取一个句子,并且一旦空格字符出现,就会将流行的字符放入标签中.我在数组数据类型中遇到问题.

这是代码.

I want to read a sentence from a textbox characterwise and as soon as the space character comes the prevoiusly occured characters are to put in a label. I am having problems in array data types.

Here is the code.

Private Sub file_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles file_open.Click

        Dim count As Integer = 0
        Dim objreader As New System.IO.StreamReader(file_name.Text)

        TextBox1.Text = TextBox1.Text & objreader.ReadLine & vbCrLf

        Dim myArray1() As Char = TextBox1.Text.ToCharArray()
        Dim myArray2 As List(Of Char) = New List(Of Char)


        For Each c As Char In myArray1
            If c <> " " Then
                myArray2.Add(c)
            Else
                id.Text = myArray2()           ' here is the issue
                Exit For
            End If
        Next

    End Sub

尝试更改以下行
Try changing the following line
id.Text = myArray2()


对此


To this

id.Text = CStr(myArray2.ToArray())


另外,请不要交叉发表问题.我在此处看到了您的其他问题 [


Also, please do not cross post questions. I have seen your other question here[^]. You might also want to consider Luc''s solution.


您不能直接将数组分配给文本框.您可以将数组的元素分配给文本框(前提是它是字符串类型).
You cannot directly assign an array to a textbox. You can assign an element of an array to a textbox (provided it is a string type).