Why does Console.WriteLine() function miss some characters within a string?

后端 未结 7 2361
野的像风
野的像风 2021-02-12 10:42

I have a string, declared as:

 string text = \"THIS IS LINE ONE \"+(Char)(13)+\" this is line 2\";

And yet, When I write Console.WriteLin

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 11:36

    This is how standard output on the console behaves.

    • "\n" ((Char)10) will move the caret to the start of the next line
    • "\r" ((Char)13) will move the caret to the start of the current line

    As such, the results are thus the first line overwritten by the second line, leaving only the extra characters that the second line couldn't overwrite.

    Since you've clarified that the string/characters have to be like that to get the behavior you want when this text is ultimately sent to the place you actually want to send it to, a dot matrix printer, then you need to test with the printer itself.

    The above behavior is localized to the standard console. If you output the same characters to "standard output" but have redirected this to a printer, it is the printer's definition on how to deal with these characters that is important, and this may be different from the standard console.

    As such, the behavior you see on the standard console is just that, the behavior of the standard console. You need to actually test with the printer to see how this behaves.

提交回复
热议问题