博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java截取2个指定字符之间的字符串
阅读量:7216 次
发布时间:2019-06-29

本文共 1128 字,大约阅读时间需要 3 分钟。

hot3.png

/**     * 截取字符串str中指定字符 strStart、strEnd之间的字符串     *      * @param string     * @param str1     * @param str2     * @return     */    public static String subString(String str, String strStart, String strEnd) {         /* 找出指定的2个字符在 该字符串里面的 位置 */        int strStartIndex = str.indexOf(strStart);        int strEndIndex = str.indexOf(strEnd);         /* index 为负数 即表示该字符串中 没有该字符 */        if (strStartIndex < 0) {            return "字符串 :---->" + str + "<---- 中不存在 " + strStart + ", 无法截取目标字符串";        }        if (strEndIndex < 0) {            return "字符串 :---->" + str + "<---- 中不存在 " + strEnd + ", 无法截取目标字符串";        }        /* 开始截取 */        String result = str.substring(strStartIndex, strEndIndex).substring(strStart.length());        return result;    }

简单粗暴的方式:

public String splitData(String str, String strStart, String strEnd) {        String tempStr;        tempStr = str.substring(str.indexOf(strStart) + 1, str.lastIndexOf(strEnd));        return tempStr;    }

 

------------------- 

作者:IT_小斯 
来源:CSDN 
原文:https://blog.csdn.net/baidu_32739019/article/details/78741273 

转载于:https://my.oschina.net/zjllovecode/blog/3000128

你可能感兴趣的文章
Linux 系统下双机HA的实现
查看>>
02_swarm mode key concepts
查看>>
Eclipse打包插件Fat Jar 解压打包
查看>>
Apache Shiro 使用手册
查看>>
CentOS mini 6.5 安装DB2 Express-C 问题处理记录
查看>>
DirectByteBuffer
查看>>
Docker Compose文件详解 V2
查看>>
Memcached的原理与应用(未完)
查看>>
基于 Confluence 6 数据中心的 SAML 单点登录设置你的身份提供者
查看>>
mysql总结
查看>>
Navicat for MySQL版本更新至v11.2.12,修复多项问题|附下载
查看>>
整理 JAVA中的IO流 (字符流和字节流两个大类)
查看>>
uefi与win8 (根据网络资料整理)
查看>>
Eclipse优化
查看>>
Log4j tutorial with Tomcat examples
查看>>
Kong 网关
查看>>
三层结构视频中的DBHelper.cs
查看>>
[转载] 信息系统项目管理师视频教程——18 项目沟通管理
查看>>
在Windows下建立QT开发环境
查看>>
Jedis、JedisPool、ShardedJedis和ShardedJedisPool,java对redis的基本操作
查看>>