Two Laptop Bag*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Please reply!" Watch "Please reply!" New topic
Author

Please reply!

zoster gibrilian
Greenhorn

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

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

Joined: Aug 20, 2001
Posts: 1815
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;
System.out.println(str);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please reply!
 
Similar Threads
Brute Force
My Custom Validator is not working as i want
split() method problem
JSF chart and Chinese font
Problem in passing request parameter