1

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

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()
4

2 回答 2

0

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

If iCounter = txtOCR.Lines.Length Then
    '...
End If
于 2013-02-26T09:07:51.913 回答
0

只需将每个中的string变量分配给特定的. 它将替换每个文本中的文本,最后它将产生符合您期望的结果。'Line'iterationwhile looptext boxiterations

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
于 2013-02-26T09:28:12.510 回答