Compare Text and count differences based on characters
Page 1 of 1
Compare Text and count differences based on characters A typing test program, where typed text is matched with a parent text
#1
Posted 15 February 2009 - 09:21 PM
I have two multiline textboxes, and I want to compare and count the text differences between them. The algorithm appears very complex.. To be exact, I need to check for the spelling mistakes (spaces and newlines can be ignored..)Can anyone please help me with this??
#2
Posted 16 February 2009 - 06:39 AM
I should not give you any code, because you did not post any, but I can help you by referring you to Google, or Yahoo or some other similar search engine - surely this has been done before. Try something like this:
http://www.google.co...amp;btnG=Search
http://www.google.co...amp;btnG=Search
#3
Posted 19 February 2009 - 12:58 AM
Well, I did try , but couldn't come up with what I wanted..I need to compare two text files and count the character differences between them..like in a typing test program.The code I came up with just checks if a word exists in the parent file, (irrespective of the position). Please suggest the changes, I need to make to my current code..
Here's the code:
Here's the code:
Dim sr As StreamReader
Dim strFile1, strFile2 As String
Dim strFile1Lines(), strFile2Lines() As String
Dim strFile1NotFile2 As String = ""
Dim strFile2NotFile1 As String = ""
' Open File1
sr = New StreamReader(file1)
strFile1 = sr.ReadToEnd()
sr.Close()
'Open File2
sr = New StreamReader(file2)
strFile2 = sr.ReadToEnd()
sr.Close()
'delimiter for splitting strings
Dim delim() As String = {" ", vbCrLf}
' Seperate the contents of File1 and File2 into words
strFile1Lines = strFile1.Split(delim, StringSplitOptions.RemoveEmptyEntries)
strFile2Lines = strFile2.Split(delim, StringSplitOptions.RemoveEmptyEntries)
' Going through each word in File 1
For Each strFile1Line As String In strFile1Lines
Dim bLineInFile2 As Boolean = False
' Compare the current word in File1 against all lines in File2
For Each strFile2Line As String In strFile2Lines
If strFile1Line = strFile2Line Then bLineInFile2 = True
Next
' If the word is in not in File2 add it to the variable strFile1NotFile2
If Not bLineInFile2 Then strFile1NotFile2 = strFile1NotFile2 & strFile1Line & vbCrLf
Next
'display the unmatched words in a richtextbox
RichTextBox1.Text = strFile1NotFile2
#4
Posted 19 February 2009 - 03:01 AM
You might try removing the whitespaces and newlines from the strings you create by reading the files, rather than splitting them. See String.Replace Method
,,,
strFile1 = strFile1.Replace(" "c, "") //' remove all spaces
...
strFile2 = strFile2.Replace(" "c, "") //' remove all spaces
...
if strFile2 <> strFile1 then
//' complain
end if
...
For i As Integer = 0 To strFile1.Length - 1
If strFile1(i) <> strFile2(i) Then
MessageBox.Show(strFile1(i) & " <> " & strFile2(i))
End If
Next
...
#5
Posted 19 February 2009 - 03:39 AM
Thanks, but that isn't helping me..
Your code compares characters at equal positions..Ex:
Original Text: I have a doll
Typed Text: I have doll
The number of typing mistakes : 1, but using u'r code, we get total no. of typing mistakes as 4. And mine shows Mistakes=0(because there is no spelling mistakes in the typed words )
I'm trying to develop something similar to the 'Compare Document' function of MS Word, where two text are compared on character level.
Is this possible??
Your code compares characters at equal positions..Ex:
Original Text: I have a doll
Typed Text: I have doll
The number of typing mistakes : 1, but using u'r code, we get total no. of typing mistakes as 4. And mine shows Mistakes=0(because there is no spelling mistakes in the typed words )
I'm trying to develop something similar to the 'Compare Document' function of MS Word, where two text are compared on character level.
Is this possible??
Page 1 of 1

Add Reply




MultiQuote

| 


