printing columns

M

Michael Pope

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?
 
M

Michael Pope

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)
 
J

Joel VanderWerf

Michael said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,663
Latest member
josh5959

Latest Threads

Top