Here you can find the source of splitStr(String str, int toCount)
public static ArrayList splitStr(String str, int toCount)
//package com.java2s; import java.util.ArrayList; public class Main { public static ArrayList splitStr(String str, int toCount) { int reInt = 0; if (str == null) return null; char[] tempChar = str.toCharArray(); int totalChars = tempChar.length; ArrayList result = new ArrayList(); int totalBytes = 0; int i = 0; while (totalBytes < str.getBytes().length) { StringBuffer reStr = new StringBuffer(); int stepInt = 0; for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) { if ((tempChar[kk] >= 0x0021) && (tempChar[kk] <= 0x007e)) { reInt += 1;// www .ja va 2 s .c o m } else { reInt += 2; } reStr.append(tempChar[kk]); i++; stepInt++; } char[] tmp = new char[totalChars - i]; for (int j = 0; j < tmp.length; j++) { tmp[j] = tempChar[stepInt + j]; } tempChar = tmp; totalBytes += reInt; reInt = 0; result.add(reStr.toString()); } return result; } }