Java String Pad Left lPad(String str, int len, char pad)

Here you can find the source of lPad(String str, int len, char pad)

Description

l Pad

License

Open Source License

Declaration

public static String lPad(String str, int len, char pad) 

Method Source Code

//package com.java2s;
/*/*from   w w  w .j a v a  2  s.c om*/
 * M2M ServiceFOTA ONM version 1.0
 *
 *  Copyright ? 2014 kt corp. All rights reserved.
 *
 *  This is a proprietary software of kt corp, and you may not use this file except in
 *  compliance with license agreement with kt corp. Any redistribution or use of this
 *  software, with or without modification shall be strictly prohibited without prior written
 *  approval of kt corp, and the copyright notice above does not evidence any actual or
 *  intended publication of such software.
 */

public class Main {

    public static String lPad(String str, int len, char pad) {
        return lPad(str, len, pad, false);
    }

    public static String lPad(String str, int len, char pad, boolean isTrim) {

        if (isEmpty(str)) {
            return null;
        }

        if (isTrim) {
            str = str.trim();
        }

        for (int i = str.length(); i < len; i++) {
            str = pad + str;
        }

        return str;
    }

    public static boolean isEmpty(String str) {

        if (str != null) {
            str = str.trim();
        }

        return (str == null || str.length() == 0);
    }

    public static String trim(String origString, String trimString) {
        int startPosit = origString.indexOf(trimString);
        if (startPosit != -1) {
            int endPosit = trimString.length() + startPosit;
            return origString.substring(0, startPosit) + origString.substring(endPosit);
        }
        return origString;
    }
}

Related

  1. lpad(String s, int length, char pad)
  2. lpad(String s, int width)
  3. lpad(String s, String fill, int len)
  4. lpad(String src, int length, char padding)
  5. lpad(String str, char pad, int len)
  6. lpad(String str, int len, char padding)
  7. LPad(String str, int length, String chr)
  8. lPad(String str, int length, String padString)
  9. lpad(String str, int size)