Java String Sub String subStringByBytes(String str, int toCount, String more)

Here you can find the source of subStringByBytes(String str, int toCount, String more)

Description

sub String By Bytes

License

LGPL

Declaration

public static String subStringByBytes(String str, int toCount, String more) 

Method Source Code

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

Related

  1. substringBetween(String str, String tag)
  2. substringBetweenStrings(String within, String pre, String post)
  3. subStringByByte(String orignal, int subcount)
  4. subStringByByte(String str, int byteLenth)
  5. substringByByteCount(String str, int byteCount)
  6. substringByCodePoint(String inputStr, int codePointStart, int codePointEnd)
  7. substringByMask(String baseString, String baseMask, String subMask)
  8. subStringByte(String str, int toCount, String more)
  9. substringBytes(String value, int byte_len)