https://www.cnblogs.com/alisapan/p/6490590.html
https://www.jb51.net/article/144305.htm
大小写转换:https://www.cnblogs.com/zhang12354/p/7944393.html
一、截取两个关键字之间的字符串
1、封装的方法
/** * 根据多个常量关键字读取日志中的动态关键字 * * @param goalStr 被读取的日志字符串 * @param startKeyword 开始读取的关键字 * @param endKeyword 结束读取的关键字 * @return 返回startKeyword与endKeyword之间的关键字 */ public String readLogKeywordByKeyword(String goalStr, String startKeyword, String endKeyword) { //step1:定位开始关键字字符串的首字符在目的字符串中的位置 int strFirstIndex = goalStr.indexOf(startKeyword); //step2:从目的字符串中截取开始关键字及之后的所有字符 String resultStr = goalStr.substring(strFirstIndex); //step3:把step2中的字符串作为目的字符串,截取某关键字之前的所有字符 resultStr = StringUtils.substringBefore(resultStr, endKeyword); return resultStr; }
2、调用测试
@Test public void testStr() { ReadLogContent readLogContent = new ReadLogContent(); String str = "creativeId=CREATIVE201908021000016055;contentData={};],;success=true;needRetry=false;errorContext=null;"; System.out.println(readLogContent.readLogKeywordByKeyword(str, "success", ";"));//3456789abc }
3、调用结果