JAVA按字符长度截取中英文混合字符串
public class Test {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubTest 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++;elselength += 2;}return length;}}