Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split WriteLine over multiple lines?

Tags:

c#

This is an example of the syntax I tried and don't want to use \n.

Console.WriteLine("x"
                  "x"
                  "x"
                  "x"
                  "x");

One call should yield:

x  
x  
x  
x  
x
like image 825
AXv52B4tSo Avatar asked Apr 28 '11 15:04

AXv52B4tSo


People also ask

How do you separate lines of code?

To break a single statement into multiple linesUse the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break.

How do you split a string into multiple lines in Python?

You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python. You can use it to join text on separate lines and create a multiline string.

How do you go to the next line in console WriteLine?

By using: \n – It prints new line. By using: \x0A or \xA (ASCII literal of \n) – It prints new line. By using: Console. WriteLine() – It prints new line.

How do you print multiple lines in Python?

"\n" can be used for a new line character, or if you are printing the same thing multiple times then a for loop should be used.


1 Answers

One call shouldn't yield that, because you've got two string literals. In fact, that won't even compile...

Try:

Console.WriteLine("x\nx");

Or at worse:

Console.WriteLine(@"x
x");
like image 178
Matthew Abbott Avatar answered Oct 13 '22 22:10

Matthew Abbott