Java String Pad Left leftPad(String srcString, char c, int length)

Here you can find the source of leftPad(String srcString, char c, int length)

Description

left Pad

License

Apache License

Declaration

public static String leftPad(String srcString, char c, int length) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String leftPad(String srcString, char c, int length) {
        if (srcString == null) {
            srcString = "";
        }//from  ww  w.j  a  v  a  2  s . c om
        int tLen = srcString.length();

        if (tLen >= length)
            return srcString;
        int iMax = length - tLen;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < iMax; ++i) {
            sb.append(c);
        }
        sb.append(srcString);
        return sb.toString();
    }
}

Related

  1. leftPad(String s, int target)
  2. leftPad(String s, int width)
  3. leftPad(String s, int z)
  4. leftPad(String srcStr, char padChar, int destLen)
  5. leftPad(String srcString, char c, int length)
  6. leftPad(String str, int len, char c)
  7. leftPad(String str, int length)
  8. leftPad(String str, int length, char c)
  9. leftPad(String str, int length, char padding)