字符串匹配的算法.
public String getMaxMatch(String a,String b) {
StringBuffer tmp = new StringBuffer();
String maxString = "";
int max = 0;
int len = 0;
char[] aArray = a.toCharArray();
char[] bArray = b.toCharArray();
int posA = 0;
int posB = 0;
while(posA
posB = 0;
while(posB<(bArray.length-max)) {
if(aArray[posA]==bArray[posB]) {
len = 1;
tmp = new StringBuffer();
tmp.append(aArray[posA]);
while((posA+len
tmp.append(aArray[posA+len]);
len++;
}
if(len>max) {
max = len;
maxString = tmp.toString();
}
}
posB++;
}
posA++;
}
return maxString;
}
相關(guān)推薦:計算機等級考試二級Java編程的三十個基本規(guī)則
計算機等級考試二級Java練習(xí)題及答案匯總