Java String Sub String substringBetween(String str, String open, String close, int fromIndex)

Here you can find the source of substringBetween(String str, String open, String close, int fromIndex)

Description

substring Between

License

Open Source License

Declaration

public static String substringBetween(String str, String open,
        String close, int fromIndex) 

Method Source Code

//package com.java2s;
/*(C) 2007-2012 Alibaba Group Holding Limited.   
 *This program is free software; you can redistribute it and/or modify   
 *it under the terms of the GNU General Public License version 2 as   
 * published by the Free Software Foundation.   
 * Authors:   /*from  w w w.  java  2 s  . c  o m*/
 *   junyu <junyu@taobao.com> , shenxun <shenxun@taobao.com>,   
 *   linxuan <linxuan@taobao.com> ,qihao <qihao@taobao.com>    
 */

public class Main {

    public static String substringBetween(String str, String tag) {
        return substringBetween(str, tag, tag, 0);
    }

    public static String substringBetween(String str, String open,
            String close) {
        return substringBetween(str, open, close, 0);
    }

    public static String substringBetween(String str, String open,
            String close, int fromIndex) {
        if ((str == null) || (open == null) || (close == null)) {
            return null;
        }

        int start = str.indexOf(open, fromIndex);

        if (start != -1) {
            int end = str.indexOf(close, start + open.length());

            if (end != -1) {
                return str.substring(start + open.length(), end);
            }
        }

        return null;
    }
}

Related

  1. substringBetween(String source, String strBegin, String strEnd)
  2. substringBetween(String str, String before, String after)
  3. substringBetween(String str, String open, String close)
  4. substringBetween(String str, String open, String close)
  5. substringBetween(String str, String open, String close)
  6. substringBetween(String str, String pos1, String pos2)
  7. substringBetween(String str, String tag)
  8. substringBetween(String str, String tag)
  9. substringBetweenStrings(String within, String pre, String post)