syncis
syncis

Reputation: 1433

string formatting and printing

I am trying to align values. I wonder why this happen :

        string value = "";

        value += string.Format("{0,-10}", "value");
        value += string.Format("{0,5}", "value");

        value += Environment.NewLine;

        value += string.Format("{0,-8}", "val");
        value += string.Format("{0,7}", "value");

        Print(value);

If i check value before i "Print" it is correct. The result is:

value     value
val       value

As they should be, but when i print "value" to my printer then they get like this :

   value     value
   val     value

I really cant understand why it changes the string when i print the text?

I have tried to use "\t" but my printer dont seem to understand "\t" because the tabs isnt printed out.

Btw: this is just a test code so you could understand the problem that i am having with the real code.

Upvotes: 1

Views: 705

Answers (2)

Bueller
Bueller

Reputation: 2344

your console uses fixed width fonts where your printer does not (at least by default). So spaces take up less space on your printer and your letters take up more or less space based on their actual width.

Upvotes: 2

agent-j
agent-j

Reputation: 27913

This could be caused by a font that uses different character widths. In non-fixed-width fonts, spaces are often narrower than letters and numbers, so it might seem that spaces are missing. Consider using Lucida Console or another fixed-width font.

Upvotes: 2

Related Questions