File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Please reply! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please reply!" Watch "Please reply!" New topic

Please reply!

zoster gibrilian

Joined: Sep 17, 2003
Posts: 7
i need to concatenate 8-length() of 0's before a string that has as length: lenght().
In other words i have to write a loop that will print out (if needed!) 0's in front of a string ... in order to make it a 8 charachter string

I can not believe that java does not have a function that prints a charachter n-times. Or does it?
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

It doesn't, but you can easily write your own:

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Another way, perhaps
String pad = "00000000";
String str = "12345";
str = pad.substring(0,pad.length()-str.length())+str;
I agree. Here's the link:
subject: Please reply!
It's not a secret anymore!