如何检查它是否是字符串vb.net的最后一行

时间:2013-02-26 09:00:12

标签: vb.net string

我有一个循环,逐行从文本框中提取字符串我希望有一个条件,如果它的最后一行我将它存储在另一个文本框中。这是我的代码

Dim builder As New StringBuilder()
Dim reader As New StringReader(txtOCR.Text)

While True
        Dim line As String = reader.ReadLine()
        If line Is Nothing Then Exit While

        Dim WordCount = New Regex("\w+").Matches(line).Count

        If WordCount = 1 And Not line.ToLower().Contains("by") Then
            builder.AppendLine(line)

        ElseIf line.ToLower().Contains("the") And Not line.ToLower().Contains("by") Then
            builder.AppendLine(line)

        ElseIf line.ToLower().Contains("an") And Not line.ToLower().Contains("by") Then
            builder.AppendLine(line)
        End If
End While
txtTitle.Text = builder.ToString()

2 个答案:

答案 0 :(得分:0)

在循环内使用计数器,然后:

If iCounter = txtOCR.Lines.Length Then
    '...
End If

答案 1 :(得分:0)

只需将string的每个'Line'中的iteration变量while loop分配给特定的text box。它将替换每个iterations中的文本,最后它将产生符合您期望的结果。

While True

        Dim line As String = reader.ReadLine()
        If line Is Nothing Then Exit While

        ....................
        ....................

        txtNew.text = line 'Assigning the variable to the separate text box

End While