首先,窗体中有两个TextBox控件,TextBox1,TextBox2,一个按钮。
方法1:直接用textbox的text属性
If Me.TextBox1.Text > "" Then
Me.TextBox2.Clear()
For i = 0 To Me.TextBox1.Lines.Length - 1
If Me.TextBox1.Lines(i).ToString > "" Then
Me.TextBox2.Text += Trim(Me.TextBox1.Lines(i).ToString) & Environment.NewLine
End If
Next
Me.TextBox2.Text = Mid(Me.TextBox2.Text, 1, Me.TextBox2.TextLength - 2)
End If
方法2:用Line()字符串数组
Dim Row1 As Integer
Dim Line() As String
If Me.TextBox1.Text > "" Then
Me.TextBox2.Clear()
Row1 = Me.TextBox1.Lines.Length - 1
j = 0
ReDim Line(Row1)
For i = 0 To Row1
If Me.TextBox1.Lines(i).ToString > "" Then
Line(j) = Trim(Me.TextBox1.Lines(i).ToString)
j += 1
End If
Next
ReDim Preserve Line(j - 1)
Me.TextBox2.Lines = Line
End If
方法3:用Line()字符串数组和ArrayList,感觉用ArrayList.Add方法很方便
Dim Row1, Row2 As Integer
Dim line() As String
Dim ArList As New ArrayList
If Me.TextBox1.Text > "" Then
Me.TextBox2.Clear()
Row1 = Me.TextBox1.Lines.Length - 1
For i = 0 To Row1
If Me.TextBox1.Lines(i).ToString > "" Then
ArList.Add(Trim(Me.TextBox1.Lines(i).ToString))
End If
Next
Row2 = ArList.Count - 1
ReDim line(Row2)
For i = 0 To Row2
line(i) = ArList.Item(i).ToString
Next
Me.TextBox2.Lines = line
End If
'''''''''''''''
请大家帮我看看,什么地方要改进的。哪一种方法比较好,或还有其他方法。讨论讨论。