Android String Sub String Get subInStringByFlag(String str, String flag)

Here you can find the source of subInStringByFlag(String str, String flag)

Description

sub In String By Flag

Declaration

public static String subInStringByFlag(String str, String flag) 

Method Source Code

//package com.java2s;

public class Main {
    public static String subInStringByFlag(String str, String flag) {
        if (isBlank(str))
            return null;
        StringBuffer sb = new StringBuffer(str);
        int index = str.lastIndexOf(flag);
        if (index < 0) {
            return str;
        } else {/*  w  w w  . j a  v a  2 s.co m*/
            str = sb.delete(sb.length() - flag.length(), sb.length())
                    .toString();
            index = str.indexOf(flag);
            if (index < 0) {
                return str;
            } else {
                return sb.deleteCharAt(0).toString();
            }
        }
    }

    public static boolean isBlank(String str) {
        if (null == str)
            return true;
        if ("".equals(str.trim()))
            return true;

        return false;
    }

    public static boolean isBlank(Long str) {
        if (null == str)
            return true;
        return false;
    }

    public static String toString(Object obj) {
        if (obj == null) {
            return "";
        }
        return obj.toString().trim();
    }
}

Related

  1. mid(String str, int beginIndex, int length)
  2. subStringByByte(String str, int startPos, int length)
  3. subStringByByte(String paramString, int beginIndex, int endIndex)
  4. subString(String source, String start, int offsetStart, String end, int offsetEnd)
  5. subString(String str, int length)
  6. substringWithoutException(String text, int startIndex, int endIndex)
  7. subString(String str)
  8. replace(String s, String oldSub, String newSub)
  9. replace(String s, String[] oldSubs, String[] newSubs)