字符串格式和打印 [英] string formatting and printing
问题描述
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);
打印(值);
如果我在打印之前检查了值,这是正确的。结果是:
pre $ value $ value $ b $ val值
code $
正如他们应该那样,但当我打印价值到我的打印机,然后他们得到这样的:
价值价值
val价值
理解为什么当我打印文本时会改变字符串?
我试图使用\ t,但是我的打印机似乎不理解\ t,因为这些标签没有打印出来。
$ b btw:这只是一个测试代码,所以你可以理解我用真正的代码所遇到的问题。
您的控制台使用固定宽度的字体,您的打印机没有(至少在默认情况下)。所以空间占用打印机的空间较少,字母会根据实际宽度占用更多或更少的空间。
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.
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.
这篇关于字符串格式和打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!