Have tried searching for an answer but not finding any matching use-case.
The goal: Merge two strings, replacing the duplicate phrases/content.
Example..
String first = "The quick brown fox jumped.";
String second = "The quick brown fox jumped, and was happy.";
// magic goes here
String intended_outcome = "The quick brown fox jumped, and was happy";
So in this case it's simple, could just do a String.IndexOf nocase ordinal.
But then consider:
String first = "Hello there. The quick brown fox jumped.";
String second = "The quick brown fox jumped, and was happy.";
// remove all punctuation, words by spaces only(to simplify)
first = Regex.Replace(first,@"[^\w\s]","");
second = Regex.Replace(second,@"[^\w\s]","");
// magic goes here
String intended_outcome = "Hello there, The quick brown fox jumped, and was happy";
- Would you recommend that I convert to an array(
first+second
combined, split by space), and then process recursively to find duplication of phrases by stepping through each word one by one? - Or loop each word, use an indexOf check to find a common word between the two (eg.
second.indexOf(av_split_first[i])!=-1
), as a start-index, and process subsequent words until all are found, replace, and recurse w/ offset?
Has anyone tackled this before? I'm targeting C#, but would be interested in any solution for any language, regex or otherwise