/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Test t = new Test(); System.out.println(t.splitStr("雪雪xx儿儿ee雪儿rr", 4));
}
public String splitStr(String sChars, int sLength) { String str = ""; int sl = 0; for (int i = 0; i < sChars.length(); i++) { if ((sChars.charAt(i) + "").equals("")) break; str += sChars.charAt(i); sl += getStrLength(sChars.charAt(i) + ""); if (sl>= sLength) { str += ","; sl=0; } } return str; }
public int getStrLength(String s) { int length = 0; for (int i = 0; i < s.length(); i++) { int ascii = Character.codePointAt(s, i); if (ascii >= 0 && ascii <= 255) length++; else length += 2;