It goes through and removes all types of line breaks from the designated text string. This tells it to replace all instance of the \r\n then replace all \n than finally replace all \r. The second piece of code with the javascript replace method removes all three types of line breaks by using this bit of a regular expression: \r\n|\n|\r. This javascript code removes all 3 types of line breaks
Var someText = "Here's some text.\n It has some line breaks that will be removed \r using Javascript.\r\n" We define the text variable that needs to be cleansed of line breaks. Here's where the javascript magic happens: In order to remove line breaks from text we must deal with all three types of line breaks as typically your text could come from any of those sources. The first type of line break (\r\n) is usually created on a windows computer, the second (\n) on Linux and the third kind of line break (\r) on an Apple computer. Line breaks in text are generally represented in three ways as either \r\n or as \n or \r. Convert text line breaks to html line break If you're looking for online tools that already do this then check out these tools:
Javascript clean text how to#
In this tutorial I'll show how to remove line breaks from regular text using some simple javascript code.