Java String Sub String substrByLength(String str, int start, int size, String markCode)

Here you can find the source of substrByLength(String str, int start, int size, String markCode)

Description

substr By Length

License

Open Source License

Declaration

public static String substrByLength(String str, int start, int size, String markCode) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String substrByLength(String str, int start, int size, String markCode) {
        String finalStr = "";
        if (str == null) {
            for (int i = 0; i < size; i++) {
                finalStr = finalStr + " ";
                return finalStr;
            }/*from w  ww .j a va 2s  .co  m*/
        }
        int length = start + size - 1;
        if (length > str.length()) {
            finalStr = str.substring(start, str.length());
        } else {
            finalStr = str.substring(start, length);
        }

        for (int i = 0; i < size - finalStr.length() + 1; i++) {
            finalStr = finalStr + markCode;
        }
        return finalStr;
    }
}

Related

  1. substract(Number n1, Number n2)
  2. substraction2(double[] a, double[] b)
  3. substractPrefixPostfix(Object obj, String prefix, String suffix)
  4. subStrBeforeDotNotIncludeDot(String str)
  5. subStrByBytes(String str, int len, String tail)
  6. subStrBytes2(String str, int byteLength)
  7. substrCount(String haystack, String needle)
  8. subStrIfNeed(final String str, int num)
  9. substring(byte[] array, int start)