Here you can find the source of substrByLength(String str, int start, int size, String markCode)
public static String substrByLength(String str, int start, int size, String markCode)
//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; } }