I think the easiest way is to break the lines into words and use a given structure, such as HashSet<string> , to check for duplicates. for example
public bool HasMatchingWord(string left, string right) { var hashSet = new HashSet<string>( left.Split(" ", StringSplitOptions.RemoveEmptyEntries)); return right .Split(" ", StringSplitOptions.RemoveEmptyEntries) .Any(x => hashSet.Contains(x)); }
Jaredpar
source share