我需要两个单词之间的字符不同
example= (1) Sunday (2) Sundey
different character i need **e**
example= (1) Monday (2) Monbuy
different character i need **bu**
最佳答案
用您提供的输入进行了测试,在这些情况下可以完美地工作
private static String getDifferentChar(String data, String compareWithData) {
if(data == null || compareWithData == null) return null;
int dataLength = data.length();
int compareWithDataLength = compareWithData.length();
String differentChar = "";
int pos =0;
if(pos<dataLength && compareWithDataLength >=dataLength) {
while(pos<dataLength) {
if(data.charAt(pos) != compareWithData.charAt(pos)) {
differentChar+= "" + compareWithData.charAt(pos);
}
pos++;
}
if(compareWithDataLength > dataLength) {
differentChar+= "" + compareWithData.substring(dataLength);
}
}
return differentChar;
}