Reputation: 1802
I need the different of characters between two words
example= (1) Sunday (2) Sundey
different character i need **e**
example= (1) Monday (2) Monbuy
different character i need **bu**
Upvotes: 0
Views: 64
Reputation: 2367
Have tested with the input you have given, working perfectly in those cases
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;
}
Upvotes: 1
Reputation: 23556
Levenshtein distance suddently comes to mind: https://www.tutorialspoint.com/cplusplus-program-to-implement-levenshtein-distance-computing-algorithm
It calculates the necessary amount of insertion, deletion and exchanges to convert one string to another, you may easily change it to fit your own criteria for string difference.
Upvotes: 0