I'm trying be able to compare two Strings and identify duplicate words. For example;
String1 = "Hello, my name is John."
String2 = "Can you tell me your name please?"
Comparing String1 and String2 would return the word; "name".
I know it is possible to split these two strings into an array of words, and then iterate over each word of each String in a 2-D array. However this is computationally expensive at O(n^2) and I was wondering if there is a faster way of doing this?
Thanks.
EDIT: Changed the example for clarity.