console.writeline and wordwrapping

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

using VS 2003

I have a console app and writing to the console looks ugly as the line wraps
at exactly 80 characters.

Short of counting every character, is there an easier way to format my
output to the console so that each line is intelligently broken at 80
characters or less when 80 characters falls within a word.

thanks
 
Kevin,

Unfortunately no, there is no pre-set way of wrapping the text. You
will have to code this yourself. It shouldn't be too hard, since you know
you will always have 80 characters per line (as opposed to drawing on the
screen in non-fixed-width fonts).

Hope this helps.
 
Thanks for the reply Nicholas.

.... I'am typing right now.

Kevin

Nicholas Paldino said:
Kevin,

Unfortunately no, there is no pre-set way of wrapping the text. You
will have to code this yourself. It shouldn't be too hard, since you know
you will always have 80 characters per line (as opposed to drawing on the
screen in non-fixed-width fonts).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

kevin said:
using VS 2003

I have a console app and writing to the console looks ugly as the line
wraps
at exactly 80 characters.

Short of counting every character, is there an easier way to format my
output to the console so that each line is intelligently broken at 80
characters or less when 80 characters falls within a word.

thanks
 
Nicholas said:
Unfortunately no, there is no pre-set way of wrapping the text. You
will have to code this yourself. It shouldn't be too hard, since you know
you will always have 80 characters per line (as opposed to drawing on the
screen in non-fixed-width fonts).

Ah, but my standard cmd prompt isn't 80 chars in width. I changed it
because I wanted more than that. If you're using .NET 2, it's become
real easy to get to the information about the Console window using
properties like Console.WindowWidth. If you're not on .NET 2, you'd have
to use the Win API function GetConsoleScreenBufferInfo - a bit more
complicated and possibly not worth the effort.

I'd say it depends: If you only want to output some long text, it's
probably just as well if it doesn't use the whole width (but poor people
who set their window to only 70 chars...). If you're writing an
application that actually works on the console interactively, you might
want to go to the trouble to make it work perfectly.



Oliver Sturm
 
Oliver,

The OP stated he wanted it broken at 80 chars, but you bring up a good
point. =)
 
kevin said:
using VS 2003

I have a console app and writing to the console looks ugly as the line wraps
at exactly 80 characters.

Short of counting every character, is there an easier way to format my
output to the console so that each line is intelligently broken at 80
characters or less when 80 characters falls within a word.

thanks

Have a google for 'pretty print'. You will probably find many
implementations in C/C++, which given that you are just doing console
output, should be easily translatable.

I'm sure there are many many ex-CS students who were forced to write
pretty printers in most every language under the sun...
 
Back
Top