Reputation: 1
How to get an specified line in an textbox and get the text from that line in an string
Upvotes: 0
Views: 1069
Reputation: 2095
Dim lines As String() = testing.Text.Split(Environment.NewLine)
then access the lines just like this
lines(0) // would be first line
Upvotes: 3
Reputation: 44931
You need to split the text box text into an array of strings based on the line separator and then, if you have enough lines, get the line from the array:
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
Upvotes: 0