Line Break Escape Converter
Convert between literal line breaks and escaped newline characters (\\n). Supports CRLF, CR, and LF line endings with bidirectional conversion.
Input
Output
Readme
What are line breaks and escape sequences?
A line break is a special character that represents the end of a line in text. In actual text, line breaks appear as physical line separations when you press Enter. However, in programming and data formats, line breaks can be represented as escape sequences-a backslash followed by a character (like \n in most programming languages). Escape sequences are a text representation of control characters that cannot be directly typed or displayed.
Different systems represent line breaks differently: Unix and modern systems use \n (Line Feed), older Mac systems used \r (Carriage Return), and Windows uses \r\n (both characters together). Converting between literal line breaks and their escaped representations is essential when working with data transfer, configuration files, and cross-platform text processing.
Tool description
This line break escape converter transforms text between literal line breaks (actual newlines that appear as separate lines) and their escaped representations (\n). It handles all common line break formats: Unix \n, Windows \r\n, and older Mac \r. This tool is invaluable when you need to include text with line breaks in JSON, configuration files, SQL queries, or other formats that require escaped line breaks.
Examples
| Input (Literal) | Output (Escaped) |
|---|---|
| Line 1 Line 2 Line 3 |
Line 1\nLine 2\nLine 3 |
| Hello World |
Hello\nWorld |
| First Second Third |
First\nSecond\nThird |
| Input (Escaped) | Output (Literal) |
|---|---|
| Text\nWith\nBreaks | Text With Breaks |
| Name\nAddress | Name Address |
Features
- Automatic format detection: Recognizes Windows (
\r\n), Unix (\n), and Mac (\r) line breaks - Bidirectional conversion: Convert literal to escaped or escaped to literal
- Preserves content: Only converts line break characters, leaving all other text unchanged
How it works
When converting literal to escaped, the tool scans the text for all types of line break characters (Windows, Mac, and Unix) and replaces them with the literal text \n. When converting escaped to literal, it finds every \n sequence and replaces it with an actual newline character. All other content remains unchanged.
Limitations
- Only handles standard
\nescape sequences; does not convert other escape characters like\t(tab) or\r(carriage return) - The tool assumes
\nrepresents a newline; if your text contains the literal string\nthat shouldn't be converted, this tool will convert it - Complex escaping scenarios with mixed escaped and literal line breaks require manual review