Newlines and Tabs in Strings

Explicit representations of newlines and tabs in strings.

This prints on two lines:

"First line.\nSecond line."

In (RefLink[InputForm, paclet:ref/InputForm]) there is an explicit ∖n to represent the newline:

InputForm[%]

The Wolfram Language keeps line breaks entered within a string:

"A string on 
two lines."

There is a newline in the string:

InputForm[%]

With a single backslash at the end of a line, the Wolfram Language ignores the line break:

"A string on \
one line."

You should realize that even though it is possible to achieve some formatting of Wolfram Language output by creating strings which contain raw tabs and newlines, this is rarely a good idea. Typically a much better approach is to use the higher-level Wolfram Language formatting primitives discussed in "String-Oriented Output Formats", "Output Formats for Numbers", and "Tables and Matrices". These primitives will always yield consistent output, independent of such issues as the positions of tab settings on a particular device.

In strings with newlines, text is always aligned on the left:

{"Here is\na string\non several lines.","Here is\nanother"}

The front end formatting construct (RefLink[Column, paclet:ref/Column]) gives more control. Here text is aligned on the right:

Column[{"First line","Second","Third"},Right]

And here the text is centered:

Column[{"First line","Second","Third"},Center]