首先,窗体中有两个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
'''''''''''''''
请大家帮我看看,什么地方要改进的。哪一种方法比较好,或还有其他方法。讨论讨论。
TextBox数据处理技巧
本文探讨了三种不同的方法来处理TextBox中的数据,包括直接使用text属性、利用Line()字符串数组及结合ArrayList的方式,对比分析了各自的优缺点。
2524

被折叠的 条评论
为什么被折叠?



