Java String Sub String substringAfter(String str, int beginChar, boolean last)

Here you can find the source of substringAfter(String str, int beginChar, boolean last)

Description

substring After

License

MIT License

Declaration

public static String substringAfter(String str, int beginChar, boolean last) 

Method Source Code

//package com.java2s;
/*!/*  ww  w  .j  a va 2s .  c  om*/
 * mifmi-commons4j
 * https://github.com/mifmi/mifmi-commons4j
 *
 * Copyright (c) 2015 mifmi.org and other contributors
 * Released under the MIT license
 * https://opensource.org/licenses/MIT
 */

public class Main {
    public static String substringAfter(String str, int beginChar, boolean last) {
        if (str == null) {
            return null;
        }
        if (beginChar < 0) {
            return str;
        }

        int idx = (last) ? str.lastIndexOf(beginChar) : str.indexOf(beginChar);
        if (idx == -1) {
            return str;
        }

        return str.substring(idx);
    }

    public static String substringAfter(String str, String beginStr, boolean last) {
        if (str == null) {
            return null;
        }
        if (beginStr == null) {
            return str;
        }

        int idx = (last) ? str.lastIndexOf(beginStr) : str.indexOf(beginStr);
        if (idx == -1) {
            return str;
        }

        return str.substring(idx);
    }

    public static int lastIndexOf(CharSequence charSeq, char ch) {
        if (charSeq == null) {
            return -1;
        }
        return lastIndexOf(charSeq, ch, charSeq.length() - 1);
    }

    public static int lastIndexOf(CharSequence charSeq, char ch, int fromIndex) {
        if (charSeq == null) {
            return -1;
        }
        for (int i = fromIndex; 0 <= i; i--) {
            char c = charSeq.charAt(i);
            if (c == ch) {
                return i;
            }
        }
        return -1;
    }

    public static int lastIndexOf(CharSequence charSeq, char[] ch) {
        if (charSeq == null) {
            return -1;
        }
        return lastIndexOf(charSeq, ch, charSeq.length() - 1);
    }

    public static int lastIndexOf(CharSequence charSeq, char ch[], int fromIndex) {
        if (charSeq == null) {
            return -1;
        }
        for (int i = fromIndex; 0 <= i; i--) {
            char c = charSeq.charAt(i);
            for (int j = 0; j < ch.length; j++) {
                if (c == ch[j]) {
                    return i;
                }
            }
        }
        return -1;
    }

    public static int indexOf(CharSequence charSeq, char ch) {
        return indexOf(charSeq, ch, 0);
    }

    public static int indexOf(CharSequence charSeq, char ch, int fromIndex) {
        if (charSeq == null) {
            return -1;
        }
        int len = charSeq.length();
        for (int i = fromIndex; i < len; i++) {
            char c = charSeq.charAt(i);
            if (c == ch) {
                return i;
            }
        }
        return -1;
    }

    public static int indexOf(CharSequence charSeq, char[] ch) {
        return indexOf(charSeq, ch, 0);
    }

    public static int indexOf(CharSequence charSeq, char[] ch, int fromIndex) {
        if (charSeq == null) {
            return -1;
        }
        int len = charSeq.length();
        for (int i = fromIndex; i < len; i++) {
            char c = charSeq.charAt(i);
            for (int j = 0; j < ch.length; j++) {
                if (c == ch[j]) {
                    return i;
                }
            }
        }
        return -1;
    }
}

Related

  1. subString4lastIndex(String string, String regex)
  2. substringAfter(final String str, final String separator)
  3. substringAfter(String s, String cs)
  4. substringAfter(String s, String substr, boolean fromend)
  5. substringAfter(String sourceStr, String expr)
  6. substringAfter(String str, String delimiter)
  7. substringAfter(String str, String separator)
  8. substringAfter(String str, String separator)
  9. substringAfter(String str, String separator)