/**
* 截取字符串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个指定字符之间的字符串的更多相关文章

  1. SQL Server 截取两个固定字符之间的字符串(案例)

    网上的问题: 参考这篇<函数PARSENAME使用和截取字符串>https://www.cnblogs.com/insus/p/10958452.html 的方法: )='||MO21|T ...

  2. php截取指定两个字符之间的字符串

    //截取指定两个字符之间的字符串 public function cut($begin,$end,$str){ $b = mb_strpos($str,$begin) + mb_strlen($beg ...

  3. 请求大神,C#如何截取字符串中指定字符之间的部分 按指定字符串分割 一分为二 c# 去除字符串中的某个已知字符

    string stra = "abcdefghijk";string strtempa = "c";string strtempb = "j" ...

  4. String replaceAll-正则匹配-截取以指定字符开头,以指定字符结尾的字符串

    scala代码块 截取以某个字符开头,以某个字符结尾的字符串 def main(args: Array[String]): Unit = { val s = "{{a61,a2,a3},{b ...

  5. delphi 截取指定符号之间的字符串-随机读取

    unit Unit1; interface uses  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...

  6. mysql中截取指定字符前后的字符串

    使用SUBSTRING_INDEX()函数substring_index(str,delim,count) str:要处理的字符串 delim:分隔符 count:分隔符计数 例子取出上述表中数组的第 ...

  7. JS字符串截取(获取指定字符后面的所有字符内容)

    function getCaption(obj){     var index=obj.lastIndexOf("\-");     obj=obj.substring(index ...

  8. Java获取两个指定日期之间的所有月份

    String y1 = "2016-02";// 开始时间 String y2 = "2019-12";// 结束时间 try { Date startDate ...

  9. PHP截取指定字符前的字符串

    $str = 'A|B||C|D'; echo substr($str,0,strpos($str, '||')); 输出:A|B

随机推荐

  1. git rebase和git merge的用法

    http://softlab.sdut.edu.cn/blog/subaochen/2016/01/git-rebase%E5%92%8Cgit-merge%E7%9A%84%E7%94%A8%E6% ...

  2. Init wms goodlocation data

    insert goodlocation: CREATE PROCEDURE [dbo].[sp_insert_goodlocation] -- Add the parameters for the s ...

  3. css实现礼券效果2

    <template> <div class="quan clear"> <div class="quanleft"> < ...

  4. C#路径中获取文件全路径、目录、扩展名、文件名称

    C#路径中获取文件全路径.目录.扩展名.文件名称常用函数 需要引用System.IO 直接可以调用Path的静态方法 class Program { static void Main(string[] ...

  5. Beep函数实现硬件蜂鸣声

    #include <Windows.h> #include <tchar.h> int WINAPI _tWinMain(HINSTANCE hInstance, HINSTA ...

  6. setoolkit 制作钓鱼网页

    由于是在虚拟机下实验,仅做示范 下载地址 git clone https://github.com/trustedsec/social-engineer-toolkit/ 终端输入setoolkit启 ...

  7. 切换用户后,/etc/profile的配置不起效

    遇到的问题 在配置linux的时候,发现一个问题:su root切换到root用户后,/etc/profile 中配置的PATH不起效果. 问题分析和疑问 是不是~/.profile,~/.bashr ...

  8. html5 css练习 下拉菜单制作

    *{    margin: 0;    padding: 0;}li{    list-style-type: none;}a{    text-decoration: none;}.ul1{marg ...

  9. Python魔法方法详解

      魔法方法 含义   基本的魔法方法 __new__(cls[, ...]) 1.__new__是在一个对象实例化的时候所调用的第一个方法 2.它的第一个参数是这个类,其他的参数是用来直接传递给__ ...

  10. Cannot locate BeanDefinitionParser for element [scoped-proxy]

    指定使用 CGLIB 而不使用 JDK 生成代理对象:注意:此两个标签必须同时出现,不然会报:Cannot locate BeanDefinitionParser for element [scope ...