Here you can find the source of substring(String text, int startPos, int endPos)
Parameter | Description |
---|---|
text | a parameter |
startPos | a parameter |
length | a parameter |
public static String substring(String text, int startPos, int endPos)
//package com.java2s; //License from project: Apache License public class Main { /**/*w w w . j av a2 s . co m*/ * substring * * @param text * @param startPos * @param length * @return */ public static String substring(String text, int startPos, int endPos) { String str = NVL(text); // enough length? str = fill(str, endPos); // get substr return str.substring(startPos, endPos).trim(); } /** * NVL - fix null value * @param String value * @param replace with * @return */ public static String NVL(String str, String replace) { if (str == null || str.trim().equals("") || str.trim().toUpperCase().equals("NULL")) return replace; return str; } /** * NVL - fix null value * @param string value * @return */ public static String NVL(String str) { return NVL(str, ""); } /** * fill * * @param value * @param length * @param fillChar * @param isLeadingFill * @return */ public static String fill(String value, int length, char fillChar, boolean isLeadingFill) { value = NVL(value); String rc = value; for (int i = 0; i < length - value.length(); i++) { if (isLeadingFill) { rc = fillChar + rc; } else { rc += fillChar; } } return rc; } /** * fill * * @param value * @param length * @param fillChar * @return */ public static String fill(String value, int length, char fillChar) { return fill(value, length, fillChar, false); } /** * fill * * @param value * @param length * @param isLeadingFill * @return */ public static String fill(String value, int length, boolean isLeadingFill) { return fill(value, length, ' ', isLeadingFill); } /** * fill * * @param value * @param length * @return */ public static String fill(String value, int length) { return fill(value, length, ' ', false); } }