p; String theNext=inputs.get(i);
int theIndex=str.indexOf(theNext);
if(theIndex==-1){//过滤掉无效关键字
inputs.remove(i);
}else if(theIndex<index){
index=theIndex;//替换下标
next=theNext;
}
}
//如果条件成立,表示串中已经没有可以被替换的关键字,否则递归处理
if(index==str.length()){
resStr.append(str);
}else{
resStr.append(str.substring(0,index));
resStr.append("<font color='#FF0000'>"+str.substring(index,index+next.length())+"</font>");
String str1=str.substring(index+next.length(),str.length());
addChild(str1,inputs,resStr);//剩余的字符串继续替换
}
return resStr;
}
|