Java String Pad Left leftPaddedString(String string, int length, char paddingChar)

Here you can find the source of leftPaddedString(String string, int length, char paddingChar)

Description

left Padded String

License

Open Source License

Declaration

public static String leftPaddedString(String string, int length, char paddingChar) 

Method Source Code

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

public class Main {
    public static String leftPaddedString(String string, int length, char paddingChar) {
        if (string.length() > length) {
            System.err.println("WARNING: String to pad is longer than expected length. Return original string.");
            return string;
        }//from ww  w  . ja v a 2s . co  m
        if (string.length() == length)
            return string;
        return String.format("%0" + (length - string.length()) + "d", 0).replace('0', paddingChar).concat(string);
    }
}

Related

  1. leftPad(String value, int makeLength, char paddingCharacter)
  2. leftPad(String value, int size, String pad)
  3. leftPad(StringBuilder pStringBuilder, int pLength, char pChar)
  4. leftPadByteArray(byte[] source, int size)
  5. leftPadded(String src, int len)
  6. leftPadding(final StringBuffer strBuf, final int bufLen, final char fill)
  7. leftPadding(String in, int count, char pad)
  8. leftPadding(String orgStr, String addStr, int strLength)
  9. leftPadInt(int number, int width)