A newline is a character used to represent the end of a line of text and the beginning of a new line. With early computers, an ASCII code was created to represent a new line because all text was on one line.

In programming languages, such as C, Java, and Perl, the newline character is represented by the ‘\n’ escape sequence. Below are examples of how the newline could be used in Perl.

#!/usr/bin/perl

Print “Hello World!” and start a new line with \nprint “Hello World!\n”;#Locate and replace any newlines in the mydata variable#and replace those newlines with a ** as the separator.

$mydata =~ s/\n/**/g;

In the first section of the example code above, Perl would first print “Hello World!” and move to the next line. In the second section of the example code, the $mydata variable would have all new lines stripped and replaced with “**”. Using this type of regular expression is helpful with parsing text with newlines or place data with newlines in a single line of text.

CR, LF, Line, Line break, Meta-character, Programming terms, White space

A newline is not the same as a carriage return.

  • Use our text tool to remove and replace newlines from any text.
  • How to create a new line in a p tag of HTML.
  • How to create a new line, not a paragraph in Microsoft Word.
  • How to start a new line in a spreadsheet cell.
  • How to move down a line in a cell within Microsoft Excel.