java截取2个指定字符之间的字符串
/**
* 截取字符串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;
}
java截取2个指定字符之间的字符串的更多相关文章
- SQL Server 截取两个固定字符之间的字符串(案例)
网上的问题: 参考这篇<函数PARSENAME使用和截取字符串>https://www.cnblogs.com/insus/p/10958452.html 的方法: )='||MO21|T ...
- php截取指定两个字符之间的字符串
//截取指定两个字符之间的字符串 public function cut($begin,$end,$str){ $b = mb_strpos($str,$begin) + mb_strlen($beg ...
- 请求大神,C#如何截取字符串中指定字符之间的部分 按指定字符串分割 一分为二 c# 去除字符串中的某个已知字符
string stra = "abcdefghijk";string strtempa = "c";string strtempb = "j" ...
- String replaceAll-正则匹配-截取以指定字符开头,以指定字符结尾的字符串
scala代码块 截取以某个字符开头,以某个字符结尾的字符串 def main(args: Array[String]): Unit = { val s = "{{a61,a2,a3},{b ...
- delphi 截取指定符号之间的字符串-随机读取
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...
- mysql中截取指定字符前后的字符串
使用SUBSTRING_INDEX()函数substring_index(str,delim,count) str:要处理的字符串 delim:分隔符 count:分隔符计数 例子取出上述表中数组的第 ...
- JS字符串截取(获取指定字符后面的所有字符内容)
function getCaption(obj){ var index=obj.lastIndexOf("\-"); obj=obj.substring(index ...
- Java获取两个指定日期之间的所有月份
String y1 = "2016-02";// 开始时间 String y2 = "2019-12";// 结束时间 try { Date startDate ...
- PHP截取指定字符前的字符串
$str = 'A|B||C|D'; echo substr($str,0,strpos($str, '||')); 输出:A|B
随机推荐
- day28:hashlib
1,继续上一小节,讲解双下内置方法,双下getitem,setitem,delitem方法,是对象可以像字典一样的来访问属性 # 普通的字典是像下面这样操作的 dic = {'k' : 'v'} di ...
- Ultimate Guide to WhatsApp for Business 2019
By Iaroslav Kudritskiy (Source: https://rocketbots.io/blog/the-ultimate-guide-to-whatsapp-business-a ...
- [git] git怎样fork一个repo
描述 我定制了一下strongswan的工程.然后想把我自己的定制变成一个repo push到远端git.tong.com与大家分享. 这个时候,应该怎么做? 如果你用过github的话.那么你可以理 ...
- shell脚本if语句的多种条件参数
if语句有多种写法 [root@shell-yankerp sh]# [ -f file ] && echo "yes" || echo "no" ...
- mysql GROUP_CONCAT 查询某个字段(查询结果默认逗号拼接)
Mysql 的 GROUP_CONCAT 函数默认将查询的结果用逗号拼接并返回一个字符串,如:李四,long,张三 1. 常用方式 select GROUP_CONCAT(user_name) use ...
- LVS,Keepalived,HAproxy区别与联系
LVS,Keepalived,HAproxy区别与联系 LVS 全称Linux Virtual Server,也就是Linux虚拟服务器,由章文嵩(现就职于于淘宝,正因为如此才出现了后来的fullna ...
- Spring Boot(一):环境搭建,建立简单项目
一.基本环境搭建 1.下载IntelliJ IDEA :http://www.jetbrains.com/idea/ 2.拖到页面最下面下载旗舰版 3.新建项目 4.设置本地Maven 5.删除多于文 ...
- python生成数据后,快速导入数据库
1.使用python生成数据库文件内容 # coding=utf-8import randomimport time def create_user(): start = time.time() ...
- 【论文阅读】Deep Mixture of Diverse Experts for Large-Scale Visual Recognition
导读: 本文为论文<Deep Mixture of Diverse Experts for Large-Scale Visual Recognition>的阅读总结.目的是做大规模图像分类 ...
- MySQL使用root权限创建用户并授权
MySql篇 1.下载并安装Mysql (1)下载地址 MySQL-8.0下载地址 (2)Mysql配置 1.home目录下命令行执行:vi .bash_profile来配置MySql绝对路径 ...