I create the following for truncating a string in java to a new string with a given number of bytes.
String truncatedValue = \"\";
String curren
you could convert the string to bytes and convert just those bytes back to a string.
public static String substring(String text, int maxBytes) {
StringBuilder ret = new StringBuilder();
for(int i = 0;i < text.length(); i++) {
// works out how many bytes a character takes,
// and removes these from the total allowed.
if((maxBytes -= text.substring(i, i+1).getBytes().length) < 0) break;
ret.append(text.charAt(i));
}
return ret.toString();
}