KaktusJack

KaktusJack

  • NA
  • 26
  • 10.5k

How to compare 2 strings with int out of errors?

Mar 17 2011 2:38 AM
I've searched online for a diff algorithm but none of them do what I am looking for. It is for a texting contest (as in cell phone) and I need the entry text compared to the master text recording the errors along the way. I am semi-new to C# and I get most of the string functions and didn't think this was going to be that hard of a problem, but alas I just can't wrap my head around it.
I have a form with 2 rich-text-boxes (one on top of the other) and 2 buttons. The top box is the master text (string) and the bottom box is the entry text (string). Every contestant is sending a text to an email account, from the email we copy and paste the text into the Entry RTB and compare to the Master RTB. For each single word and single space counts as a thing to check. And for every error add 1 sec. to their time.

Examples:
  • Hello there! <= 3 checks (2 words and 1 space)
  • Helothere! <= 2 errors (Helo and space)
  • Hello there!! <= 1 error (extra ! at end of there!)
  • Hello there! How are you? <= 9 checks (5 words and 4 spaces)
  • Helothere!! How a re you? <= still 9 checks, 4 errors(helo, no space, extra !, and a space in are)
  • Hello there!@ Ho are yu?? <= 3 errors (@ at end of there!, no w, no o and extra ? (all errors are still under the 1 word)
What I have so far:
I've created 6 arrays (3 for master, 3 for entry) and they are
  • Char array of all chars
  • String array delimited with " " and also counting the " "
  • Int array with length of the string in each string array
My biggest trouble is if the entry text is wrong and shorter than the master. I keep getting IndexOutOfRange exceptions (understandably) but can't fathom how to go about checking and writing the code to compensate.
I hope I have made myself clear enough as to what I need help with. If anyone could give some code examples or something to shoot me in the right path would be very helpful.


Answers (22)