如何在文本框中获取特定行并从字符串中获取该行的文本
答案 0 :(得分:3)
Dim lines As String() = testing.Text.Split(Environment.NewLine)
然后像这样访问行
lines(0) // would be first line
答案 1 :(得分:0)
您需要根据行分隔符将文本框文本拆分为字符串数组,然后,如果您有足够的行,则从数组中获取行:
Dim asLines As String()
Dim wLineToGet As Integer = 2
asLines = TextBox1.Text.Split(New String() {Environment.NewLine}, StringSplitOptions.None)
If asLines IsNot Nothing AndAlso asLines.Length >= wLineToGet Then
MessageBox.Show("Line " & wLineToGet & " = " & asLines(wLineToGet - 1))
Else
MessageBox.Show("There are not enough lines in the textbox to retrieve line " & wLineToGet)
End If