Java String Sub String subStringIgnoreCase(String str, String separator, Integer stratNum, Integer endNum)

Here you can find the source of subStringIgnoreCase(String str, String separator, Integer stratNum, Integer endNum)

Description

sub String Ignore Case

License

Open Source License

Declaration

public static final String subStringIgnoreCase(String str, String separator, Integer stratNum, Integer endNum) 

Method Source Code

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

public class Main {
    /**@see #subString(String, String, Integer, Integer, Boolean)
     * @author hcqt@qq.com*///from w  ww.  java 2s . c  o  m
    public static final String subStringIgnoreCase(String str, String separator, Integer stratNum, Integer endNum) {
        return subString(str, separator, stratNum, endNum, true);
    }

    /**@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);
    }

    /**@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;
    }
}

Related

  1. substringEquals(final String s1, final int fromIndex1, final int toIndex1, final String s2, final int fromIndex2, final int toIndex2)
  2. subStringExe(String s, String jmp, String sb, String se)
  3. substringFromMatch(String match, String string)
  4. substringFromMultiValuedFields(int start, int end, String[] fieldValues, int offsetGap, String interFieldJoiner)
  5. substringGuarded(String s, int position, int count)
  6. substringInBetween(String name, String prefix, String delimiter)
  7. substringL(String s, int i, int len)
  8. substringLinesWithTokenOfEOL( String originalString, String stringToBeInserted)
  9. substringMatch(CharSequence str, int index, CharSequence substring)