如果TextBox1是:
football
tennis
basketball
TextBox2.Text是:
volleyball
basketball
我想从TextBox1.Text中删除包含来自TextBox2.Text的一行的每一行,所以在那之后TextBox1将是:
football
tennis
(篮球被删除,因为textbox2包含它)
答案 0 :(得分:0)
使用String.Split和Enumerable.Except:
' Convert newline-separated TextBox contents to string arrays
Dim all = TextBox1.Text.Split({vbCrLf}, StringSplitOptions.None)
Dim toRemove = TextBox2.Text.Split({vbCrLf}, StringSplitOptions.None)
Dim filtered = all.Except(toRemove)
' Fill the text box with the result (newline-separated)
TextBox1.Text = String.Join(vbCrLf, filtered)
(我所有的VB代码示例都假设Option Strict On和Option Infer On。)
答案 1 :(得分:0)
Dim filter As String() = fleska.Split(New [Char]() {CChar(vbCrLf)})
For Each line As String In filter
TextBox1.Text = TextBox1.Text.Replace(line, "").Trim()
Next
这将删除TextBox2中TextBox1中的所有行。