Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Formatting text documents in Java?

 
M Burke
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to generate a report that has preset columns. I tried using tabs but each row is still misaligned. How can I align the rows if the text is variable size?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pad the strings to a fixed size. I have a little library to right and left justify strings for this kind of thing.

I patterned all my string helper methods after the REXX langauge which has lovely string handling
 
M Burke
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, is this util class avalaible in Java?
 
Tomas Hirsch
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also made a small hack to get some text formatting.
I'll put it up on:
http://www.fos.su.se/~tompa/JAVA/FormatString.txt
so you can check it out.
It's a private class like Math, so you invoke it by saying:
FormatString.xxxxAdjust( String foo, int bar )
where
xxxx = right, left, or middle.
foo = the string you wnat to adjust.
bar = the number of characters long you want the formatted text to be.
Best regards!
Tomas
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For grins, as an optional argument specify what character or string to use for padding. It's cool to put leading zeros or center a string for a heading or eyecatcher:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic