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

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

Description

substring

License

Apache License

Declaration

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

Method Source Code

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

public class Main {

    public static String substring(String str, int toCount, String more) {
        int reInt = 0;
        String reStr = "";
        if (str == null)
            return "";
        char[] tempChar = str.toCharArray();
        for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) {
            String s1 = str.valueOf(tempChar[kk]);
            byte[] b = s1.getBytes();
            reInt += b.length;// w  ww  .  j a  v a 2s. c  om
            reStr += tempChar[kk];
        }
        if (toCount == reInt || (toCount == reInt - 1))
            reStr += more;
        return reStr;
    }
}

Related

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