Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formatting a string

 
Grant Morris
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic