Here you can find the source of leftPadString(String sValue, int iLength, String sPadString)
Parameter | Description |
---|---|
sValue | String to be padded |
iLength | Length of the string after padded. |
sPadString | Character to add. |
public static String leftPadString(String sValue, int iLength, String sPadString)
//package com.java2s; public class Main { /**//from www.j a v a2 s . c om * Left pad the string with the specific character and maximum length. * @param sValue String to be padded * @param iLength Length of the string after padded. * @param sPadString Character to add. * @return */ public static String leftPadString(String sValue, int iLength, String sPadString) { String sZeros = ""; String sResult = ""; int iRemainLength = 0; iRemainLength = iLength - sValue.length(); //System.out.println("iRemainLength: " + iRemainLength); //build '0's if (iRemainLength != 0) { while (iRemainLength-- > 0) { sZeros += sPadString; } } sResult = sZeros + sValue; //System.out.println("after add zero: " + sResult); return sResult; } }