jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes String formatting in JDK 1.4.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String formatting in JDK 1.4.2" Watch "String formatting in JDK 1.4.2" New topic
Author

String formatting in JDK 1.4.2

Raksha Shetty
Greenhorn

Joined: Aug 17, 2010
Posts: 3
Hi,

I need to format Strings to be of a certain width. Could anyone suggest any in-built methods for this?
I've seen some String.format() method stuff but it doesn't seem to exist in JDK 1.4; only JDK1.5 and above.
There's surely gotta be a better way than, say, tabbing !?

Thanks,
Raksha
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Check for third-party libraries, otherwise it's pretty trivial to write your own left- and right-padding methods. And welcome to JavaRanch!
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

string.format will make your life more busy in coding


SCJP6.0,My blog Ranchers from Delhi
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

shanky sohar wrote:string.format will make your life more busy in coding

That's only available in Java 1.5 onwards, which is why he's asking the question.
Raksha Shetty
Greenhorn

Joined: Aug 17, 2010
Posts: 3
Thanks for the responses ..
I have created my own little padding function to solve the formatting issue.

Now I face another issue, which is that the text that I have padded appears perfectly in some settings and is all misaligned in certain other settings of the browser.

Any way I can make this small piece of code robust enough to handle all these browser settings problems?

Thanks again!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Padding etc. on the *browser* should be handled via CSS and the DOM, not on the Java side.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String formatting in JDK 1.4.2
 
Similar Threads
Recursive constructor invocation
Head First Java 2nd Ed. Correction?...
java.lang.NoClassDefFoundError: org/hibernate/MappingException
Jar files required to use org.w3c.dom.* and javax.xml.*
Ubuntu + Java 7