Here you can find the source of substring(String str, int len)
public static String substring(String str, int len)
//package com.java2s; /**/*from www .ja v a 2 s . c om*/ * 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 substring(String str, int len) { len = len * 2; StringBuffer sb = new StringBuffer(); int counter = 0; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c < 255) { counter++; } else { counter = counter + 2; } if (counter > len) { break; } sb.append(c); } return sb.toString(); } }