Here you can find the source of subStringByByte(String str, int startPos, int length)
public static String subStringByByte(String str, int startPos, int length)
//package com.java2s; public class Main { public static String subStringByByte(String str, int startPos, int length) { if (str == null || str.length() == 0) { return ""; }/* w w w .j a v a 2 s.c o m*/ StringBuffer sb = new StringBuffer(); int byteLen = 0; for (int i = 0; i < str.length(); i++) { int ascii = Character.codePointAt(str, i); if (ascii >= 0 && ascii <= 255) { byteLen++; } else { byteLen += 2; } if (byteLen >= startPos + 1 && byteLen <= length) { sb.append(str.charAt(i)); } else { break; } } return sb.toString(); } }