Here you can find the source of subStringByBytes(String str, int toCount, String more)
public static String subStringByBytes(String str, int toCount, String more)
//package com.java2s; /**// w w w.ja v a 2 s . c o m * * Methods Descrip:Converts a line of text into an array of lower case words * using a BreakIterator.wordInstance(). * <p> * * This method is under the Jive Open Source Software License and was * written by Mark Imbriaco. * * @param text * a String of text to convert into an array of words * @return text broken up into an array of words. * */ public class Main { public static String subStringByBytes(String str, int toCount, String more) { int reInt = 0; StringBuilder reStr = new StringBuilder(); char[] tempChar = str.toCharArray(); for (int kk = 0; kk < tempChar.length; kk++) { char c = tempChar[kk]; byte[] b = String.valueOf(c).getBytes(); reInt += b.length; if (toCount >= reInt) { reStr.append(c); } else { break; } } reStr.append(more); return reStr.toString(); } }