School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,125 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,046 people online right now. Registration is fast and FREE... Join Now!



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 Rate Topic: -----

#1 nadiya_hafis  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 9
  • Joined: 11-February 09


Dream Kudos: 0

Post icon  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??
Was This Post Helpful? 0
  • +
  • -


#2 MrWobbles  Icon User is offline

  • D.I.C Head
  • Icon
  • Group: Contributors
  • Posts: 235
  • Joined: 11-April 08


Dream Kudos: 25

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
Was This Post Helpful? 0
  • +
  • -

#3 nadiya_hafis  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 9
  • Joined: 11-February 09


Dream Kudos: 0

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:
	  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



Was This Post Helpful? 0
  • +
  • -

#4 n8wxs  Icon User is online

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • Icon
  • Group: Expert w/DIC++
  • Posts: 1,775
  • Joined: 06-January 08


Dream Kudos: 0

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
...


Was This Post Helpful? 0
  • +
  • -

#5 nadiya_hafis  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 9
  • Joined: 11-February 09


Dream Kudos: 0

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??
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month