Java String Pad Left lpad(String str, String chr, int length)

Here you can find the source of lpad(String str, String chr, int length)

Description

Description:Pad string to the left

License

Open Source License

Parameter

Parameter Description
original string to be padded
string to pad
location of string to pad

Return

the new string

Declaration

public static String lpad(String str, String chr, int length) 

Method Source Code

//package com.java2s;
/*/*from  w w w . j av  a2  s  .  c  o m*/
 * $RCSfile: LogStringUtil,v $$
 * $Revision: 1.0  $
 * $Date: 2010-12-09  $
 *
 * Copyright (C) 2011 GyTech, Inc. All rights reserved.
 *
 * This software is the proprietary information of GyTech, Inc.
 * Use is subject to license terms.
 */

public class Main {
    /**
     * <p>Description:Pad string to the left </p>
     * @param original string to be padded
     * @param string to pad
     * @param location of string to pad
     * @return the new string
     */
    public static String lpad(String str, String chr, int length) {
        String retVal = str;
        for (int i = 0; i < length - str.length(); i++)
            retVal = chr + retVal;

        return retVal;
    }
}

Related

  1. lpad(String str, int len, char padding)
  2. LPad(String str, int length, String chr)
  3. lPad(String str, int length, String padString)
  4. lpad(String str, int size)
  5. lpad(String str, int totalPadAmount, String padChar)
  6. lPad(String string, char[] padding, int length)
  7. lPad(String target, String fix, int length)
  8. lPad(String val, int length, String padChar)
  9. lpadding(String s, int n, String padding)