文本框替换和拆分不工作的vb.net

时间:2016-04-11 10:11:01

标签: vb.net replace split

我一直在用简单的事情挣扎太多,就像我发布的那样。

我正在开发一个vb.net中的UI,它从机器中收集一些信息。信息收集到TextBox:

Private Sub ReceivedText(ByVal [text] As String)
    If Me.TextBox2.InvokeRequired Then
        Dim x As New SetTextCallBlack(AddressOf ReceivedText)
        Me.Invoke(x, New Object() {(text)})
    Else
        Me.TextBox2.Text &= [text]
    End If
End Sub

然后我将该信息收集到datagridview或某些标签以显示简单信息。

Sub dgv()

    Dim sup2 = TextBox2.Text.Replace("#", "").Replace(">", " "c)
    Dim sup() = sup2.Split(" "c, "#", vbCrLf, vbTab)

    With DataGridView1
        .Rows(0).Cells(0).Value = sup(1).ToString
        .Rows(0).Cells(1).Value = sup(7).ToString
        .Rows(0).Cells(3).Value = sup(4).ToString
    End With
    Button5.Enabled = True
    Button6.Enabled = True
End Sub

这很好用!!!

但是当我尝试使用下面的代码填充标签时,它将无法正常工作!

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Thread.Sleep(250)

    Dim final = TextBox2.Text.Replace("#", "").Replace("SN", " "c)
    Dim final2() = final.Split(" "c, "#", vbCrLf, vbTab)
    Label1.Text = final2(0).ToString
    Textbox2.Text= final2(0).ToString

End Sub

有人能帮助我吗?标签没有文本..文本框获取所有内容。

顺便说一句,文本框是多行的,如果我将文本粘贴到Microsoft Word中,它会带有标签和额外的空格。

编辑:从[与Multiline Textbox to Datagridview]

相关的微软词中打印屏幕

wordprintscreen

Edit2:这太奇怪了..

如果我这样做

Label1.Text = "Testing" & TextBox2.Text

它只在标签上显示“测试”..

0 个答案:

没有答案