Java实现文本中的关键字高亮,匹配所有长度
这个方法还不完整,后面想起来再看,直接放代码
public static String getHeightlightWord(String textWord, String key){ StringBuffer sb = new StringBuffer(""); String tempWord = textWord == null? "" : textWord.trim(); String tempKey = key == null? "" : key.trim(); if("".equals(tempWord) || "".equals(tempKey)){ return tempWord; }else { sb.append(tempWord); } String upperWord = tempWord.toUpperCase(); String upperKey = tempKey.toUpperCase(); if(!upperWord.contains(upperKey)){ return tempWord; }else { int keyLen = upperKey.length(); int thisMathIndex = 0; List
以上代码可实现一次高亮,余下的问题就在于如何多次改变字符串的长度后能定位到需要更改的字符串(即多次高亮),打个卡先,有空再弄