in c or c++
the function comlen is defined such
int comlen(char *p,char *q){
int i=0;
while *p && (*p++==*q++)
i++;
return i;
}
Is this code equivalent of this function?
int comlen(String s,String m){
int i=0;
while (i<s.length() && s.charAt(i)==m.charAt(i)){
i++;
}
return i;
}
Would I be correct in assuming this function returns how many characters are identical starting at the beginning of the string?
You may want to check out Apache Commons Lang
StringUtilsand itsindexOfDifferencemethod.Otherwise, this function should work (but I haven’t tested it):
Note that CharSequence is an interface that is used by
String,StringBuffer, andStringBuilderrather than justString.