|XP is just a number
Re: Is it possible to find the matching words and the percentage of matching words between two texts?by McDarren (Abbot)
|on Dec 21, 2012 at 08:48 UTC
A simple approach would be to build two hashes from the strings, and then compare the hashes.So you might do something like:
You do the same for the second string, and then to compare you simply iterate through one of the hashes and increment a counter if each word is present in the other hash. Something like so:
To find the total number of words in either string, you simply count the number of keys in the hash, e.g.
And then it's just a simple calculation.