GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes formatting a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "formatting a string" Watch "formatting a string" New topic
Author

formatting a string

Grant Morris
Greenhorn

Joined: Aug 08, 2001
Posts: 8
I am trying to format a string to look like an html table without using html.
Sample output goal:

I don't know how to take into account different lengths of the values. For instance, if value2 is 15 characters long, it pushes value3 and value4 over. This is bad because I have a fixed width that I am working with. And if value6 is very small (3 characters) value7,8,9 are misaligned.

OK, I know everything got messed up, but imagine the headings and the values line up like a normal table.
Any help or ideas are appreciated.
Thanks

[This message has been edited by Grant Morris (edited August 08, 2001).]
(edited by Cindy to format example table)
[This message has been edited by Cindy Glass (edited August 08, 2001).]
Larry Anderson
Greenhorn

Joined: Aug 06, 2001
Posts: 26
Have you tried escape characters like \t (tab) or anything? Is this just a formatting problem? You can also use the .length property on a string to get its length.
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
First of all, make sure you're using a font where all the characters are the same width. This will make your job much easier.
Something you might want to try:
Figure out the longest allowable value width (say, X characters).
Pick a slightly wider size to be the width of each row (Y characters).
As each value is added to the "table" figure (and this is in pseudocode):

That's ugly pseudocode, I know, but hopefully you'll get the idea.
Originally posted by Grant Morris:
I am trying to format a string to look like an html table without using html.
Sample output goal:
Heading1 Heading2 Heading3
value1 value2 value3 value6 value7 value8

I don't know how to take into account different lengths of the values. For instance, if value2 is 15 characters long, it pushes value3 and value4 over. This is bad because I have a fixed width that I am working with. And if value6 is very small (3 characters) value7,8,9 are misaligned.

OK, I know everything got messed up, but imagine the headings and the values line up like a normal table.
Any help or ideas are appreciated.
Thanks

[This message has been edited by Grant Morris (edited August 08, 2001).]


There's nothing more dangerous than a resourceful idiot. ---Dilbert
 
GeeCON Prague 2014
 
subject: formatting a string