public static String subStringByByte(String str, int beginIndex, int endIndex) {
if (beginIndex < 0) throw new StringIndexOutOfBoundsException(beginIndex);
if (beginIndex > endIndex) throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
if (beginIndex == endIndex) return "";
int byteLength = 0;
String returnString = "";
for (int i = 0; byteLength < endIndex && i < str.length(); i++) {
char c = str.charAt(i);
byteLength += (31 < c && c < 128) ? 1 : 2;
if (byteLength > beginIndex)
returnString += c;
}
return returnString;
}