Line Separators

Line separators are a funny problem in itself. Each operating system uses different kind of escape sequences to determine a new line.

  • Windows: \r\n
  • Unix/Linux/Mac OS X: \n
  • pre-OSX Mac: \r

Orignially, the write head of typewriters could only do few tasks. I listed the most important ones below:

  • Write symbol and move the cursor one column to the right.
  • \r | carriage return | CR | Move cursor to the first column of the line.
  • \n | line feed         | LF | Move cursor to the next row/line at the same column.
  • \b | backspace     | BS | Move cursor one column back.
  • \t | horizontal tab  | HT | Move cursor to the next tab-stop.
In order to get the cursor to the beginning of the new line, you needed to use a carriage return followed by a line feed. This behaviour resulted in the \r\n escape sequence of windows. Others simplified it by selecting either \n or \r.

In Java, which is plattform independent, you get the plattform dependent escape sequence by obtaining the system property named line.separator.

String lineSeparator = System.getProperty("line.separator");

Other plattform specific system properties as the path.separator (backslash or slash) can be found at this guide.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s