Here you can find the source of leftPad(String csIn, int nRequiredLength, char cFill)
public static String leftPad(String csIn, int nRequiredLength, char cFill)
//package com.java2s; /*//from w w w . j a v a 2s . co 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 leftPad(String csIn, int nRequiredLength, char cFill) { String csOut = new String(); int nLgStringIn = csIn.length(); int nNbcharToPad = nRequiredLength - nLgStringIn; if (nNbcharToPad > 0) { for (int n = 0; n < nNbcharToPad; n++) { csOut = csOut + cFill; } csOut = csOut + csIn; } else // Keep only leftmost chars { csOut = csIn.substring(0, nRequiredLength); } return csOut; } }