Here you can find the source of splitEx(String str, String spilter)
public static String[] splitEx(String str, String spilter)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; public class Main { public static String[] splitEx(String str, String spilter) { if (str == null) { return null; }/*from w w w .jav a2 s . co m*/ if ((spilter == null) || (spilter.equals("")) || (str.length() < spilter.length())) { String[] t = { str }; return t; } ArrayList al = new ArrayList(); char[] cs = str.toCharArray(); char[] ss = spilter.toCharArray(); int length = spilter.length(); int lastIndex = 0; for (int i = 0; i <= str.length() - length;) { boolean notSuit = false; for (int j = 0; j < length; ++j) { if (cs[(i + j)] != ss[j]) { notSuit = true; break; } } if (!(notSuit)) { al.add(str.substring(lastIndex, i)); i += length; lastIndex = i; } else { ++i; } } if (lastIndex <= str.length()) { al.add(str.substring(lastIndex, str.length())); } String[] t = new String[al.size()]; for (int i = 0; i < al.size(); ++i) { t[i] = ((String) al.get(i)); } return t; } public static String subString(String src, int length) { if (src == null) { return null; } int i = src.length(); if (i > length) { return src.substring(0, length); } return src; } }