[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

printing columns

Michael Pope

7/16/2008 4:51:00 AM

I'm trying to print some data to the terminal in columns and haven't
seen a way to do it properly. I've tried "fred".center(80) to try and
center the text at column 80 but when I start entering data before
"fred" it starts to push "fred" over to the right.

Is there a way to print at a specific column regardless of what text is
on the same line before hand or after?
--
Posted via http://www.ruby-....

2 Answers

Michael Pope

7/16/2008 4:54:00 AM

0

I just worked it out, I was using a + instead of the proper , to
separate my text.

EG:
wrong way
print "hi" + "fred".center(80)

proper way
print "hi", "fred".center(80)

Michael Pope wrote:
> I'm trying to print some data to the terminal in columns and haven't
> seen a way to do it properly. I've tried "fred".center(80) to try and
> center the text at column 80 but when I start entering data before
> "fred" it starts to push "fred" over to the right.
>
> Is there a way to print at a specific column regardless of what text is
> on the same line before hand or after?

--
Posted via http://www.ruby-....

Joel VanderWerf

7/16/2008 5:06:00 AM

0

Michael Pope wrote:
> I'm trying to print some data to the terminal in columns and haven't
> seen a way to do it properly. I've tried "fred".center(80) to try and
> center the text at column 80 but when I start entering data before
> "fred" it starts to push "fred" over to the right.
>
> Is there a way to print at a specific column regardless of what text is
> on the same line before hand or after?

Use an excape char sequence to move forward?

$ ruby -e 'print "0123456789"*8; print "\r"; puts
"fred".center(80).gsub(" ", "\e[C")'
01234567890123456789012345678901234567fred23456789012345678901234567890123456789


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407