提取 Java 中两个字符串之间的差异差异:火柴:补丁:
嗨,我有两个字符串:
String hear = "Hi My name is Deepak"
+ "\n"
+ "How are you ?"
+ "\n"
+ "\n"
+ "How is everyone";
String dear = "Hi My name is Deepak"
+ "\n"
+ "How are you ?"
+ "\n"
+ "Hey there \n"
+ "How is everyone";
我想获取“嘿,那里\n”的听觉字符串中不存在的内容。我找到了一个方法,但在这种情况下它失败了:
static String strDiffChop(String s1, String s2) {
if (s1.length() > s2.length()) {
return s1.substring(s2.length() - 1);
} else if (s2.length() > s1.length()) {
return s2.substring(s1.length() - 1);
} else {
return "";
}
}
任何人都可以帮忙吗?