Here you can find the source of subStrBytes2(String str, int byteLength)
public static String[] subStrBytes2(String str, int byteLength)
//package com.java2s; public class Main { public static String[] subStrBytes2(String str, int byteLength) { String[] result = new String[] { "", "" }; if (str != null && getStringByteLength(str) > byteLength) { String tmp = ""; char c; int iCount = 0; int i = 0; for (i = 0; iCount < byteLength; i++) { c = str.charAt(i);/*from w w w. j a va2 s . c om*/ if (c < 0x7f) { iCount++; } else { iCount += 2; } tmp = tmp + c; } for (int j = i; j < str.length(); j++) { result[1] += str.charAt(j); } result[0] = tmp; } else { result[0] = str; } return result; } public static int getStringByteLength(String str) { char c; int iCount = 0; for (int i = 0; str != null && i < str.length(); i++) { c = str.charAt(i); if (c < 0x7f) { iCount++; } else { iCount += 2; } } return iCount; } }