| Author |
string alignment, output to screen
|
david rialto
Greenhorn
Joined: Sep 30, 2008
Posts: 5
|
|
Im trying to align some string output to the screen. left, center or right alignment. i've been searching but i have not found anything other than padding the output. i just think thats too specific, like it will only work for this program i'm working on, id like it to be something i could use again. any ideas? dr
|
 |
Taariq San
Ranch Hand
Joined: Nov 20, 2007
Posts: 189
|
|
|
What might be different about the requirements in another program?
|
 |
david rialto
Greenhorn
Joined: Sep 30, 2008
Posts: 5
|
|
well you would have to go through and change the padding for whatever new data your trying to represent. If you had something general that would just handle the spacing lets say alignRight(data) for example it would be easy to call and use no matter what. FYI what im doing is making a paragraph where the user gets to choose the alignment. so what i did as of now, is make the paragraph 100 characters wide. then for right alignment, i did int startPosition = 100-currentLine.length(), and used that value as the starting position for output. for center alignment do the same but divide startPosition by 2, and start the output there.
|
 |
david rialto
Greenhorn
Joined: Sep 30, 2008
Posts: 5
|
|
|
sorry if that post doesnt make sense i didnt read over it. just typed it and pressed add reply.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
Find the Formatter class and read about the % tags and the - option.
|
 |
 |
|
|
subject: string alignment, output to screen
|
|
|