Here you can find the source of substring2ByteString(String str, int endIndex)
private static String substring2ByteString(String str, int endIndex)
//package com.java2s; public class Main { private static String substring2ByteString(String str, int endIndex) { if (str == null) { return null; }/*from www . ja v a 2s.c om*/ byte[] strByte = str.getBytes(); int i, strLen; strLen = strByte.length; if (strLen <= endIndex) { return str; } int cnt = 0; for (i = 0; i < endIndex; i++) { if ((((int) strByte[i]) & 0xff) > 0x80) { cnt++; } } if ((cnt % 2) == 1) { i--; } return new String(strByte, 0, i); } }