public class Sub { /** * ====按字节长度截取字符串====== * 注意:长度是以byte为单位的,一个汉字是2个byte * @param str :要截取的字符串 * @param toCount 截取数目 * @param more 截取后追加内容 * @return 截取结果 */ public String substring(String str, int toCount, String more) { int reInt = 0; String reStr = ""; if (str == null) return ""; char[] tempChar = str.toCharArray(); for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) { String s1 = str.valueOf(tempChar[kk]); byte[] b = s1.getBytes(); reInt += b.length; reStr += tempChar[kk]; } if (toCount == reInt || (toCount == reInt - 1)) reStr += more; return reStr; } }


1659552772 LV1
2023年5月9日
1358849392 LV21
2023年3月1日
menmenge LV1
2021年10月26日
fendo LV5
2019年11月23日
acanwang
2019年10月28日
暂无贡献等级
dongzhan LV12
2019年5月6日
ALDe先森 LV8
2019年2月21日
1211413075 LV14
2019年1月12日
Delimar LV10
2018年11月20日
mwlmwl
2018年10月9日
暂无贡献等级