Java String Pad Right rightPad(String csIn, int nRequiredLength, char cFill)

Here you can find the source of rightPad(String csIn, int nRequiredLength, char cFill)

Description

right Pad

License

LGPL

Declaration

public static String rightPad(String csIn, int nRequiredLength, char cFill) 

Method Source Code

//package com.java2s;
/*//from w  w  w . j a  v a2s.c  o  m
 * JLib - Publicitas Java library v1.2.0.
 *
 * Copyright (c) 2005, 2006, 2007, 2008, 2009 Publicitas SA.
 * Licensed under LGPL (LGPL-LICENSE.txt) license.
 */

public class Main {
    public static String rightPad(String csIn, int nRequiredLength, char cFill) {
        String csOut = new String();
        int nLgStringIn = csIn.length();
        int nNbcharToPad = nRequiredLength - nLgStringIn;
        if (nNbcharToPad > 0) {
            csOut = csIn;
            for (int n = 0; n < nNbcharToPad; n++) {
                csOut = csOut + cFill;
            }
        } else // Keep only leftmost chars
        {
            csOut = csIn.substring(0, nRequiredLength);
        }

        return csOut;
    }
}

Related

  1. rightPad(byte[] bytes, int length, byte padByte)
  2. rightPad(final String input, final int size)
  3. rightPad(final String str, final int size, final char padChar)
  4. rightPad(String _str, int _size, char _padChar)
  5. rightPad(String field, char padding, int width)
  6. rightPad(String in, char padding, int length)
  7. rightPad(String in, int len, String pad)
  8. rightPad(String input, char padding, int length)