【Java】+字符串

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、调用结果

 

转载于:https://www.cnblogs.com/danhuai/p/10978487.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值