Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何合并两个多行文本框_Vb.net_Textbox_Multiline - Fatal编程技术网

Vb.net 如何合并两个多行文本框

Vb.net 如何合并两个多行文本框,vb.net,textbox,multiline,Vb.net,Textbox,Multiline,我需要在vb net中组合两个多行文本框,如下所示: 文本框1: a b c d 文本框2: 1 2 3 四, 文本框3: a1 b2 c3 d4 只是一个有三个文本框的表单。以及一个按钮,用于合并/组合/连接t3中t1和t2的每个值 我的一个尝试是: Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click For Each l

我需要在vb net中组合两个多行文本框,如下所示:
文本框1:
a
b
c
d

文本框2:
1
2
3
四,

文本框3:
a1
b2
c3
d4
只是一个有三个文本框的表单。以及一个按钮,用于合并/组合/连接t3中t1和t2的每个值

我的一个尝试是:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    For Each line In TextBox1.Lines
        For Each linex In TextBox2.Lines
            Me.TextBox3.Text += line & linex
            Me.TextBox3.Text += Environment.NewLine
        Next
    Next

End Sub

但是两条线(a1、a2、a3、b1、b2、b3…)的结果组合(线=线X)可能有很多方法可以做到这一点。我已经在下面向您展示了一个,但您可能会假设textbox 2包含与textbox 1相同数量的行。它不包含任何验证,但会按照您的要求执行

查看评论以了解发生了什么

'Declare empty string for concatinating the text used in textbox 3
    Dim lsText As String = String.Empty
    'Loop for the count of lines in the textbox starting at an index of 0 for pulling data out
    For i As Integer = 0 To TextBox1.Lines.Count - 1
        'Check if lsText has already been assigned a value
        If lsText = String.Empty Then
            'If is has not then you know its the first so dont need a carriage return line feed simply take both values at that index
            lsText = TextBox1.Lines(i) & TextBox2.Lines(i)
        Else
            'Otherwise you want the new value on a new line
            lsText = lsText & vbCrLf & TextBox1.Lines(i) & TextBox2.Lines(i)
        End If
    Next
    'Set the textbox text to the finished concatination
    TextBox3.Text = lsText

我将使用一个整数作为循环中的计数器,循环将以count的值从每个循环中提取字母,并每次增加count

您试图做的事情非常简单,所以我不会提供任何代码-您无法以这种方式有效地学习

只需知道,您需要过滤换行符,知道每个文本框中有多少个“char”,并使用循环。 或者其他许多方式,但我认为我所暗示的很简单,应该是您已经演示过的大约5行代码


祝你好运。继续发布你正在尝试的内容,如果我觉得你正在尝试,我会给予帮助。虽然现在我要睡觉了。

你自己做过什么工作吗?如果是,请张贴。如果不是的话,你会发现人们不太可能为你做没有报酬的工作。这很简单,你在谷歌上搜索过……或者尝试过自己:)快乐编码