I have three RichTextBoxes
. I want to compare all the words of RichTextbox1
with Richtextbox2
one by one with space or comma as the de
First we will declare some variables to shorten our writing work. We'll then use the For Each command.
Here we will take two rounds to scan the differences, first of Richtextbox1
which is not in Richtextbox2
and vice versa. The different characters will keep adding to the variable diff1
and diff 2
and at the end we will compile both of them in RichTextbox3
.
It will work on the diff
algorithm.
Dim txt1(RichTextBox1.Text.Split(" ").Length) As String
Dim txt2(RichTextBox2.Text.Split(" ").Length) As String
txt1 = RichTextBox1.Text.Split(" ")
txt2 = RichTextBox2.Text.Split(" ")
Dim diff1 As String = "" 'Differences between 1 and 2
Dim diff2 As String = "" 'Differences between 2 and 1
For Each diff As String In txt1
If Array.IndexOf(txt2, diff.ToString) = -1 Then
diff1 += diff.ToString & " "
End If
Next
For Each diff As String In txt2
If Array.IndexOf(txt1, diff.ToString) = -1 Then
diff2 += diff.ToString & " "
End If
Next
RichTextbox3.Text = diff1 & diff2
End Sub
Hope it would work perfectly!