2015-11-05 152 views
0

您好,我試圖從HTML網頁獲取特定的單詞,並試圖通過加載HTML源代碼到文本框然後過濾出來。如何刪除vb.net不包含特定字詞的Richtextbox行

我現在正在使用這個至關重要的是我知道,但我怎麼能融合在一起,它會檢查兩個單詞在1循環?

Dim Filter1 = "filterword1" 
    Dim Filter2 = "filterword2" 


    TextBox1.Text = WebBrowser1.DocumentText 
    TextBox2.Text = WebBrowser1.DocumentText 

    Dim lines As New List(Of String) 
    lines = TextBox1.Lines.ToList 
    For i As Integer = lines.Count - 1 To 0 Step -1 
     If Not Regex.IsMatch(lines(i), Filter1) Then 
      lines.RemoveAt(i) 
     End If 
    Next 

    TextBox1.Lines = lines.ToArray 


    Dim lines1 As New List(Of String) 
    lines1 = TextBox3.Lines.ToList 
    For i As Integer = lines1.Count - 1 To 0 Step -1 
     If Not Regex.IsMatch(lines1(i), Filter2) Then 
      lines1.RemoveAt(i) 
     End If 
    Next 

    TextBox1.Lines = lines1.ToArray 
+1

嘗試使用foreach循環 – c4pricorn

回答

0

我得到它的工作:

Const filter = "(Filterword1)|(Filterword2)|(Filterword3)|(Filterword4)" 
    Dim lines As New List(Of String) 
     lines = TextBox2.Lines.ToList 
     For i As Integer = lines.Count - 1 To 0 Step -1 
      If Not Regex.IsMatch(lines(i), filter) Then 
       lines.RemoveAt(i) 
      End If 
     Next 
相關問題