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

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

Description

sub String Nobit

License

LGPL

Declaration

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

Method Source Code

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

Related

  1. substringLinesWithTokenOfEOL( String originalString, String stringToBeInserted)
  2. substringMatch(CharSequence str, int index, CharSequence substring)
  3. substringMatch(CharSequence str, int index, CharSequence substring)
  4. substringMatches(final String source, final String substring, final boolean checkBoundaries)
  5. substringMore(String s, int maxlen)
  6. subStringNotEncode(String subject, int size)
  7. subStringRight(String str, int length)
  8. substrings(String str, int start, int end)
  9. subStrings(String str1, String str2)