jbu*_*483 22 c# string console char console.writeline
我有一个字符串,声明为:
string text = "THIS IS LINE ONE "+(Char)(13)+" this is line 2";
Run Code Online (Sandbox Code Playgroud)
然而,当我写作时Console.WriteLine(text);,
的输出是:
this is line 2E
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?或者是因为我是愚蠢的并且缺少明显的东西?
为什么不打印:
THIS IS LINE ONE [CR] //where the CR is a non printed character
this is line 2
Run Code Online (Sandbox Code Playgroud)
编辑
请注意:这不是 '如何添加回车'问题.
Ale*_* K. 58
(char)13是一个滑架返回(给左边距当前行)
THIS IS LINE ONE \r this is line 2"
Run Code Online (Sandbox Code Playgroud)
被解释为:
Print THIS IS LINE ONE
then *return* and print this is line 2
The overlap is: E
So you see: this is line 2E
ang*_*son 20
这是控制台上的标准输出的行为方式.
"\n"((Char)10)将把插入符号移动到下一行的开头"\r"((Char)13)将把插入符号移动到当前行的开头因此,结果因此是第二行覆盖的第一行,仅留下第二行不能覆盖的额外字符.
既然你已经澄清了字符串/字符必须像那样才能获得你想要的行为,当这个文本最终被发送到你真正想要发送到的地方,一个点阵打印机,那么你需要测试打印机本身.
上述行为已本地化为标准控制台.如果输出相同的字符为"标准输出"但这个重定向到打印机,是打印机对如何处理这些字符是很重要的定义,这可能是不同的,从标准的控制台.
因此,您在标准控制台上看到的行为就是标准控制台的行为.您需要使用打印机进行实际测试以查看其行为方式.
如果您想要此行为:
THIS IS LINE ONE [CR] //where the CR is a non printed character
this is line 2
Run Code Online (Sandbox Code Playgroud)
你需要这个代码:
char a = (char)10;
string text = "THIS IS LINE ONE" + a + "this is line 2"
Console.WriteLine(text);
Run Code Online (Sandbox Code Playgroud)
回车符((字符)13)是用于将设备的位置重置为一行文本开头的控制字符或机制,因为您会遇到此行为.就像我说你需要(char)13你的情况.
| 归档时间: |
|
| 查看次数: |
2735 次 |
| 最近记录: |