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

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

Description

substring

License

Apache License

Declaration

public static String substring(String str, int toCount) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String substring(String str, int toCount) {
        if (str == null)
            return "";
        int reInt = 0;
        StringBuilder reStr = new StringBuilder();
        char[] tempChar = str.toCharArray();
        int len = tempChar.length;
        for (int kk = 0; (kk < len && toCount > reInt); kk++) {
            char currentChar = tempChar[kk];
            String s1 = String.valueOf(currentChar);
            byte[] b = s1.getBytes();
            int bLen = b.length;
            if (reInt + bLen > toCount) {
                break;
            }/*from   w  ww .j  a va 2s.c  o m*/
            reInt += bLen;
            reStr.append(currentChar);
        }
        reStr.trimToSize();
        return reStr.toString();
    }
}

Related

  1. substring(String str, int start)
  2. substring(String str, int start)
  3. substring(String str, int start, int end)
  4. substring(String str, int start, int end)
  5. subString(String str, int start, int end)
  6. substring(String str, int toCount, String more)
  7. substring(String str, String delim)
  8. subString(String string, int beginIndex, int length)
  9. subString(String string, int index)