Java String Split by Separator split(String strToSplit, String strSeparator, int iLimit)

Here you can find the source of split(String strToSplit, String strSeparator, int iLimit)

Description

split

License

Open Source License

Declaration

public static String[] split(String strToSplit, String strSeparator, int iLimit) 

Method Source Code

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

public class Main {

    public static String[] split(String strToSplit, String strSeparator, int iLimit) {
        java.util.ArrayList tmpList = new java.util.ArrayList();
        int iFromIndex = 0;
        int iCurIndex = strToSplit.length();
        String strUnitInfo = "";
        int iCurCounts = 0;
        while ((iCurIndex != -1) && (iFromIndex <= strToSplit.length()) && (iCurCounts < iLimit)) {
            iCurIndex = strToSplit.indexOf(strSeparator, iFromIndex);
            if (iCurIndex == -1) {
                strUnitInfo = strToSplit.substring(iFromIndex, strToSplit.length());
            } else {
                strUnitInfo = strToSplit.substring(iFromIndex, iCurIndex);
                iFromIndex = iCurIndex + strSeparator.length();
            }// ww  w  . jav  a2 s.  c  o m
            tmpList.add(strUnitInfo);
            iCurCounts++;
        }
        int iCounts = tmpList.size();
        String tmpArray[] = new String[iCounts];
        for (int i = 0; i < iCounts; i++) {
            tmpArray[i] = (String) tmpList.get(i);
        }
        return tmpArray;
    }
}

Related

  1. split(String str, char separatorChar, boolean preserveAllTokens)
  2. split(String str, String separator)
  3. split(String str, String separator)
  4. split(String str, String separator, boolean preserveEmptyToken)
  5. split(String string, char separator)
  6. split(String text, String separators, String brackets)
  7. splitAll(String str, char separatorChar)
  8. splitAndTrim(String tags, String separator)
  9. splitBySeparator(String path, String separator)