Question

I have two NSString, for example: stringOne = @"1760254913042013"; stringTwo = @"4917602549030391";

I need to compare both strings to find out if both have some string in common. In the example this common string would be @"17602549". Trying to avoid writing some specific code, I been searching in NSScanner, CFString, NSString methods but nothing seems to solve this problem. Some help would be greatly appreciated.

Was it helpful?

Solution

Your two strings have many strings in common, such as "30", "91", and every substring of "17602549". It appears you're looking for the longest substring that two strings have in common.

Google "Objective-C longest common substring", and you'll find this method on Wikibooks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top