Here you can find the source of leftPad(StringBuilder pStringBuilder, int pLength, char pChar)
Parameter | Description |
---|---|
pStringBuilder | The StringBuffer object to pad. |
pLength | The length to pad to. |
pChar | The character to pad with. |
public static StringBuilder leftPad(StringBuilder pStringBuilder, int pLength, char pChar)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww . ja va2 s . c o m*/ * Similar to the Oracle lpad command. Left pads a string. * * @param pStringBuilder The StringBuffer object to pad. * @param pLength The length to pad to. * @param pChar The character to pad with. * @return StringBuilder the chomped string. */ public static StringBuilder leftPad(StringBuilder pStringBuilder, int pLength, char pChar) { StringBuilder lTempBuffer = new StringBuilder(pLength); while ((lTempBuffer.length() + pStringBuilder.length()) < pLength) { lTempBuffer.append(pChar); } lTempBuffer.append(pStringBuilder); return lTempBuffer; } /** * Similar to the Oracle lpad command. Left pads a string. * * @param pStr The String object to pad. * @param pLength The length to pad to. * @param pChar The character to pad with. * @return String the padded string. */ public static String leftPad(String pStr, int pLength, char pChar) { return leftPad(new StringBuilder(pStr), pLength, pChar).toString(); } /** * Similar to the Oracle lpad command. Left pads a string. * * @param pStr The String object to pad. * @param pLength The length to pad to. * @return String the padded string. */ public static String leftPad(String pStr, int pLength) { return leftPad(new StringBuilder(pStr), pLength, ' ').toString(); } }