已尝试搜索答案但未找到任何匹配的用例。
目标:合并两个字符串,替换重复的短语/内容。
示例..
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";
所以在这种情况下它很简单,可以只做一个String.IndexOf nocase序数。
但后来考虑一下:
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";
first+second
合并,按空格分割),然后递归处理以逐个单步执行每个单词来查找重复的短语吗? second.indexOf(av_split_first[i])!=-1
),作为起始索引,并处理后续单词,直到找到所有单词,替换并递归w / offset?以前有人解决过这个问题吗? 我的目标是C#,但对任何语言,正则表达式或其他方面的任何解决方案感兴趣