java截取2个指定字符之间的字符串

1/** 2 * 截取字符串str中指定字符 strStart、strEnd之间的字符串 3 * 4 * @param string 5 * @param str1 6 * @param str2 7 * @return 8 */ 9 public static String subString(String str, String strStart, String strEnd) { 10 11 /* 找出指定的2个字符在 该字符串里面的 位置 */ 12 int strStartIndex = str.indexOf(strStart); 13 int strEndIndex = str.indexOf(strEnd); 14 15 /* index 为负数 即表示该字符串中 没有该字符 */ 16 if (strStartIndex < 0) { 17 return "字符串 :---->" + str + "<---- 中不存在 " + strStart + ", 无法截取目标字符串"; 18 } 19 if (strEndIndex < 0) { 20 return "字符串 :---->" + str + "<---- 中不存在 " + strEnd + ", 无法截取目标字符串"; 21 } 22 /* 开始截取 */ 23 String result = str.substring(strStartIndex, strEndIndex).substring(strStart.length()); 24 return result; 25 }
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

一篇文章带你了解JavaScript日期

日期对象允许您使用日期(年、月、日、小时、分钟、秒和毫秒)。一、JavaScript的日期格式一个JavaScript日期可以写为一个字符串:ThuFeb02201909:59:51GMT0800(中国标准时间)或者是一个数字:1486000791164写数字的日期,指定的毫秒数自1970年1月1日00:00:00到现在。1\.显示日期使用

java将前端的json数组字符串转换为列表

记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang

JS 苹果手机日期显示NaN问题

问题描述newDate("2019122910:30:00")在IOS下显示为NaN原因分析带的日期IOS下存在兼容问题解决方法字符串替换letdateStr"2019122910:30:00";datedateStr.repl