Java String Sub String subStringAfterIgnoreCase(String str, String separator, Integer num)

Here you can find the source of subStringAfterIgnoreCase(String str, String separator, Integer num)

Description

sub String After Ignore Case

License

Open Source License

Declaration

public static final String subStringAfterIgnoreCase(String str, String separator, Integer num) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**@see #subStringAfter(String, String, Integer, boolean)
     * @author hcqt@qq.com*/// ww  w  .j ava2  s .  co m
    public static final String subStringAfterIgnoreCase(String str, String separator, Integer num) {
        return subStringAfter(str, separator, num, true);
    }

    /**@see #subStringAfter(String, String, Integer, Boolean)
     * @author hcqt@qq.com*/
    public static final String subStringAfterIgnoreCase(String str, String separator) {
        return subStringAfter(str, separator, 1, true);
    }

    /**@see #subStringBefore(String, String, Integer, boolean)
     * @author hcqt@qq.com*/
    public static final String subStringAfter(String str, String separator, Integer num) {
        return subStringAfter(str, separator, num, false);
    }

    /**@see #subStringBefore(String, String, Integer, boolean)
     * @author hcqt@qq.com*/
    public static final String subStringAfter(String str, String separator) {
        return subStringAfter(str, separator, 1, false);
    }

    /**@see #subStringBefore(String, String, Integer, boolean)
     * @author hcqt@qq.com*/
    public static final String subStringAfter(String str, String separator, Integer num, Boolean ignoreCase) {
        if (null == str) {
            return null;
        }
        if (null == separator) {
            return null;
        }
        if (Integer.signum(num) == 0) {
            return null;
        }
        if (ignoreCase == null) {
            ignoreCase = Boolean.FALSE;
        }
        int i = indexOf(str, separator, num, ignoreCase);
        if (i == -1) {
            return null;
        } else {
            return str.substring(i + separator.length());
        }
    }

    /**@see #indexOf(String, String, Integer, Boolean)
     * @author hcqt@qq.com*/
    public static final int indexOf(String str, String separator, Integer num) {
        return indexOf(str, separator, num, false);
    }

    public static final int indexOf(String str, String separator, Integer num, Boolean isIgnoreCase) {
        if (isIgnoreCase == null) {
            isIgnoreCase = Boolean.FALSE;
        }
        if (null == str) {
            return -1;
        }
        if (null == separator) {
            return -1;
        }
        if (isIgnoreCase) {
            str = str.toUpperCase();
            separator = separator.toUpperCase();
        }
        if (null == num) {
            num = Integer.valueOf(0);
        }
        if (Integer.signum(num) == 0) {
            return -1;
        } else if (Integer.signum(num) == 1) {
            int j = -1;
            for (int i = 0; i < num; i++) {
                if (j == -1) {
                    j = str.indexOf(separator, 0);
                } else {
                    j = str.indexOf(separator, j + 1);
                }
                if (j == -1) {
                    break;
                }
            }
            return j;
        } else if (Integer.signum(num) == -1) {
            int j = -1;
            for (int i = 0; i < Math.abs(num); i++) {
                if (j == -1) {
                    j = str.lastIndexOf(separator);
                } else {
                    j = str.lastIndexOf(separator, j - 1);
                }
                if (j == -1) {
                    break;
                }
            }
            return j;
        }
        return -1;
    }

    /**@see #subString(String, String, Integer, Integer, Boolean)
     * @author hcqt@qq.com*/
    public static final String subString(String str, String separator, Integer stratNum, Integer endNum) {
        return subString(str, separator, stratNum, endNum, false);
    }

    /**@author hcqt@qq.com*/
    public static final String subString(String str, String separator, Integer stratSeparatorNum,
            Integer endSeparatorNum, Boolean ignoreCase) {
        if (str == null || separator == null || stratSeparatorNum == null || endSeparatorNum == null) {
            return null;
        }
        int startIndex = indexOf(str, separator, stratSeparatorNum, ignoreCase);
        if (startIndex == -1) {
            return null;
        }
        startIndex = startIndex + separator.length();
        int endIndex = indexOf(str, separator, endSeparatorNum, ignoreCase);
        if (endIndex == -1) {
            return null;
        }
        if (startIndex >= endIndex) {
            return null;
        }
        return str.substring(startIndex, endIndex);
    }
}

Related

  1. substringAfter(String text, int index)
  2. substringAfter(String text, String after)
  3. substringAfter(String value, char delim)
  4. substringAfterFirstIndex(String value)
  5. substringAfterIfExist(String source, String rev)
  6. substringAfterLast(final String str, final String separator)
  7. substringAfterLast(final String str, final String separator)
  8. substringAfterLast(final String value, final String searchValue)
  9. substringAfterLast(String input, String delimiter)