1

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.

1
  • Sure you're printing in a monospaced font? Commented Jun 23, 2011 at 13:22

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

2 Comments

You mean i should change my font on the printer?
@syncis, that might work. It depends on how you are printing. Are you using something like a FlowDocument? If so, change the font on the document.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.