Java String Sub String substring(String str, int len)

Here you can find the source of substring(String str, int len)

Description

substring

License

LGPL

Declaration

public static String substring(String str, int len) 

Method Source Code

//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();
    }
}

Related

  1. substring(String str, int beginIndex, int endIndex)
  2. substring(String str, int beginIndex, int len)
  3. subString(String str, int end)
  4. substring(String str, int index, int length)
  5. subString(String str, int len)
  6. subString(String str, int num, String token)
  7. substring(String str, int off, int len)
  8. subString(String str, int offset, int leng)
  9. substring(String str, int start)