Here you can find the source of subStringNobit(String str, int toCount, String more)
public static String subStringNobit(String str, int toCount, String more)
//package com.java2s; /**//from w ww. j av 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 subStringNobit(String str, int toCount, String more) { if (str != null) { if (str.getBytes().length > toCount) { return subStringByBytes(str, toCount, more); } else { return str; } } else { return ""; } } 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(); } }