On Wed, 07 Sep 2005 13:48:02 GMT, "Ike" <> wrote or
quoted :
>Is there something in the API for left-padding an int with, say, 0's when
>converting to a String, such that, say 1 becomes "01" ? -Ike
make a slight mod to this code:
/**
* Pads the string out to the given length by applying blanks on
the left.
*
* @param s
* String to be padded/chopped.
* @param newLen
* length of new String desired.
* @param chop
* true if Strings longer than newLen should be truncated
to newLen
* chars.
* @return String padded on left/chopped to the desired length.
*/
public final static String leftPad ( String s, int newLen, boolean
chop )
{
int grow = newLen - s.length();
if ( grow <= 0 )
{
if ( chop )
{
return s.substring( 0, newLen );
}
else
{
return s;
}
}
else if ( grow <= 30 )
{
return " ".substring( 0, grow
) + s;
}
else
{
return rep( ' ', grow ) + s;
}
} // end leftPad
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.