I have two strings and I want to compare them.
edit To clarify I’d like to find the longest number of consecutive words the strings have in common.
For example the string:
“Eminent Domain for Modern : Daily MTG : Magic: The Gathering”
and
“Building On A Budget: Eminent Domain For Modern”
would return 4, since both strings contain “eminent domain for modern” which contains 4 words.
however, if simply finding the number of words in common is faster then that method would be acceptable… I’m not sure the best way to do either…
Read up on the NSString Class Reference and NSArray Class Reference for details, but here’s an approach.
Use the
NSStringmethodto remove anything that isn’t a space or letter. Then use the method
to convert the string into an
NSArraywhere each element is a word. Do this for each of the two strings you wish to compare. Then loop through the elements of the one array and use theNSArraymethodto see if the second array also contains that word. Try that, and if you get stuck at a specific point, then post the code you have and ask again for help. Good luck.