数组数据类型问题 [英] Array data types issue

查看:96
本文介绍了数组数据类型问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是代码.

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).


这篇关于数组数据类型问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆