Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Formatting

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
Hi, I want to display information in a set of columns, so I need to know how to have a string to occupy a certain length, so that if the actual string is less than that length, it adds spaces, for greater than, it truncates it. Is there something that exists for this, or would I have to create it myself?

Thanks
 
You'd have to create it yourself. You can write a simple padString method that will add leading or trailing spaces to a String or truncate it to a specified length to fit a fixed width column format.
 
There's plenty of s/w for formatting output available. Not everthing is equally usefull, but anyway.

If you search for "Java" and "printf" (e.g. on Google) you will find lots of hits. Not all of it is freeware.

HTH
Pieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top