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 }
java截取2个指定字符之间的字符串
Wesley13
2021-10-11
1088 1 0
点赞
收藏
评论区
加载中...