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

后端 未结 7 2369
野的像风
野的像风 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:40

    If you want this behavior:

    THIS IS LINE ONE [CR] //where the CR is a non printed character 
    this is line 2
    

    You need this code:

            char a = (char)10;
            string text = "THIS IS LINE ONE" + a + "this is line 2"
    
            Console.WriteLine(text);
    

    A carriage return((Char) 13) is a control character or mechanism used to reset a device's position to the beginning of a line of text, because of that you experience this behavior. Like I said you need (char)13 for your case.

提交回复
热议问题