0

如何在文本框中获取指定的行并从字符串中获取该行的文本

4

2 回答 2

3
Dim lines As String() = testing.Text.Split(Environment.NewLine)

然后像这样访问这些行

lines(0) // would be first line
于 2012-08-09T19:22:33.930 回答
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
于 2012-08-09T19:18:13.867 回答