Java String Split split(String strSource, String strReg)

Here you can find the source of split(String strSource, String strReg)

Description

split

License

Open Source License

Declaration

public static String[] split(String strSource, String strReg) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {

    public static String[] split(String strSource, String strReg) {
        if (strSource == null)
            return null;
        if (strReg == null || strReg.equals(""))
            return new String[] { strSource };

        ArrayList arrLst = new ArrayList();
        splitA(strSource, strReg, arrLst);

        String arrRslt[] = new String[arrLst.size()];
        return (String[]) arrLst.toArray(arrRslt);
    }//from  ww  w  . ja v a2s  . c  o  m

    private static void splitA(String strSource, String strReg, ArrayList arrLst) {
        int iFind = strSource.indexOf(strReg);
        if (iFind == -1) {
            arrLst.add(strSource); // return strSource;
            return;
        }
        int nRegLen = strReg.length();
        int nSourceLen = strSource.length();
        arrLst.add(strSource.substring(0, iFind));

        splitA(strSource.substring(iFind + nRegLen, nSourceLen), strReg, arrLst);
    }
}

Related

  1. split(String str, String splitter)
  2. split(String str, String token)
  3. split(String string)
  4. split(String string)
  5. split(String string, String seperator)
  6. split(String text)
  7. split(String text)
  8. split(String text)
  9. split(String text, String token)