Java String Pad Left leftPadding(final StringBuffer strBuf, final int bufLen, final char fill)

Here you can find the source of leftPadding(final StringBuffer strBuf, final int bufLen, final char fill)

Description

Left Pad Stringbuffer with special char

License

Open Source License

Parameter

Parameter Description
strBuf Target buffer
bufLen Buffer length
fill Char to fill

Return

a padded StringBuffer

Declaration

public static StringBuffer leftPadding(final StringBuffer strBuf, final int bufLen, final char fill) 

Method Source Code

//package com.java2s;
/*/*ww w. j ava 2  s. co  m*/
 * Utility.java
 *
 * HomePage :  http://www.codeproject.com/csharp/TraceTool.asp
 * Download :  http://sourceforge.net/projects/tracetool/
 * See License.txt for license information
 *
 * Author : Thierry Parent
 * Version : 12.3
 *
 * Provide some utility functions
 */

public class Main {
    /**
     * Left Pad Stringbuffer with special char
     * @param strBuf Target buffer
     * @param bufLen Buffer length
     * @param fill Char to fill
     * @return a padded StringBuffer
     */
    public static StringBuffer leftPadding(final StringBuffer strBuf, final int bufLen, final char fill) {
        while (strBuf.length() < bufLen)
            strBuf.insert(0, fill);
        return strBuf;
    }
}

Related

  1. leftPad(String value, int size, String pad)
  2. leftPad(StringBuilder pStringBuilder, int pLength, char pChar)
  3. leftPadByteArray(byte[] source, int size)
  4. leftPadded(String src, int len)
  5. leftPaddedString(String string, int length, char paddingChar)
  6. leftPadding(String in, int count, char pad)
  7. leftPadding(String orgStr, String addStr, int strLength)
  8. leftPadInt(int number, int width)
  9. leftPadMultiline(String input, char padChar, int padWidth)