Question Check/compare if the String/Text

ryoka012

Active member
Joined
Oct 13, 2011
Messages
32
Programming Experience
Beginner
Hi,

Can anyone point me in the right direction.
How can i compare/check a text/string to see if they are exactly the same in per character.(even the spaces can be check.)

Example:

Correct Data: The quick brown fox jump over the lazy dog.
Entered Data: tHE quick brown fox jump over the Lazy Dog.

number of error in "The" is 3. because they are not exactly the same..

Thanks..
 
Hi,

You can use the Char Structure to compare like for like characters in two strings. Have a look at this example but please note that this will only ever work correctly if the two strings are of the exact same length. If they are not the same length then you would automatically be comparing strings which would be out of synchronisation with each other, not to mention, the exceptions that would be thrown:-

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
  Dim correctData As String = "The quick brown fox jump over the lazy dog."
  Dim enteredData As String = "tHE quick brown fox jump over the Lazy Dog."
 
  If enteredData.Length = enteredData.Length Then
    For index As Integer = 0 To correctData.Length - 1
      Dim correctChar As Char = correctData(index)
      Dim enteredChar As Char = enteredData(index)
 
      If Not enteredChar.Equals(correctChar) Then
        MsgBox(String.Format("Correct Char is {0} and Entered Char is {1}", correctChar, enteredChar))
      End If
    Next
  End If
End Sub


Hope that helps.

Cheers,

Ian
 
Back
Top