Lev Leetian
Lev Leetian

Reputation: 63

Checking for typographical error / comparing strings

I'm currently making a language learning app and I want to check where the user made a typo and notify him where he made the typo. For example, the "correct answer" is TODAY IS GREAT but they only typed TDAY IS GREAT or TDAYIS GREAT, in which case the only mistake is in the O of TODAY and I need to make that O bold to emphasize (I know how to make it bold I just need to know the location). Can anyone suggest a good algorithm for this? Thanks!

EDIT: Finally used it, and while it works great at pointing out the number of mistakes, I'm having trouble finding the index of where the mistake is. For example, the user answer is "TEAM" but the correct answer is "THEME". In that case, I should mark the H and the second E. I tried to put the start and end index but it gets even more confusing which letter to mark if for example the string is extremely long and there are even more duplicate consecutive letters in the substring (especially in the korean language). Could anyone give me some ideas on how to do this? Thanks!

Upvotes: 0

Views: 427

Answers (1)

jacobappleton
jacobappleton

Reputation: 538

Have you tried the "Longest Common Subsequence" algorithm?

http://en.wikipedia.org/wiki/Longest_common_subsequence_problem

Upvotes: 2

Related Questions