Java Utililty Methods String Sub String

List of utility methods to do String Sub String

Description

The list of methods to do String Sub String are organized into topic(s).

Method

StringsubstringBetween(String s, String part1, String part2)
substring Between
String sub = null;
int i = s.indexOf(part1);
int j = s.indexOf(part2, i + part1.length());
if (i != -1 && j != -1) {
    int nStart = i + part1.length();
    sub = s.substring(nStart, j);
return sub;
...
StringsubstringBetween(String source, String strBegin, String strEnd)
substring Between
if (null == source)
    return null;
int index = source.indexOf(strBegin);
int indexEnd = source.indexOf(strEnd);
if (index < 0)
    index = 0 - strBegin.length();
if (indexEnd < 0)
    indexEnd = source.length();
...
StringsubstringBetween(String str, String before, String after)
substring Between
int fPos = str.indexOf(before);
if (fPos != -1) {
    str = str.substring(fPos + before.length());
} else {
    return "";
int sPos = str.indexOf(after);
if (sPos != -1) {
...
StringsubstringBetween(String str, String open, String close)
substring Between
if (str == null || open == null || close == null) {
    return null;
int start = str.indexOf(open);
if (start != -1) {
    int end = str.indexOf(close, start + open.length());
    if (end != -1) {
        return str.substring(start + open.length(), end);
...
StringsubstringBetween(String str, String open, String close)
substring Between
if (str == null || open == null || close == null) {
    return null;
int start = str.indexOf(open);
if (start != -1) {
    int end = str.indexOf(close, start + open.length());
    if (end != -1) {
        return str.substring(start + open.length(), end);
...
StringsubstringBetween(String str, String open, String close)

Gets the String that is nested in between two Strings.

if (str == null || open == null || close == null) {
    return null;
int start = str.indexOf(open);
if (start != INDEX_NOT_FOUND) {
    int end = str.indexOf(close, start + open.length());
    if (end != INDEX_NOT_FOUND) {
        return str.substring(start + open.length(), end);
...
StringsubstringBetween(String str, String open, String close, int fromIndex)
substring Between
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);
...
StringsubstringBetween(String str, String pos1, String pos2)
substring Between
int p1 = str.indexOf(pos1);
String sub = str.substring(p1 + pos1.length());
int p2 = sub.indexOf(pos2);
sub = sub.substring(0, p2);
return sub;
StringsubstringBetween(String str, String tag)

Gets the String that is nested in between two instances of the same String.

A null input String returns null .

return substringBetween(str, tag, tag);
StringsubstringBetween(String str, String tag)
substring Between
return substringBetween(str, tag, tag);