Home  >  Article  >  Web Front-end  >  How to remove carriage return in javascript

How to remove carriage return in javascript

藏色散人
藏色散人Original
2021-03-30 14:21:366101browse

Javascript method to remove carriage return: first open the corresponding js file content; then pass "str.replaceAll("(\n|\r|(\r\n)|(\u0085)|(\ u2028)|(\u2029))", "")" can be used to remove the carriage return and line feed symbols.

How to remove carriage return in javascript

The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to remove carriage return and line feed symbols in Javascript

In different operating systems, the carriage return and line feed symbols are different, see below:

First let’s talk about \n,\r,\t

\n Soft return:

in Windows means a line break and returns to the beginning of the next line

in In Linux and Unix, it only means line break, but it will not return to the beginning of the next line.

\r Soft spaces:

in Linux and unix means returning to the beginning of the current line.

In Mac OS, it means breaking a line and returning to the beginning of the next line, which is equivalent to the effect of \n in Windows.

\t Tab (move to next column)

A few notes:

They are valid in strings represented by double quotes or delimiters, and in single quotes The string represented is invalid.

\r\n is generally used together to represent the Enter key on the keyboard (in Linux and Unix). You can also just use \n (in Windwos). In Mac OS, use \r to represent Return. car!

\tRepresents the "TAB" key on the keyboard.

Newline symbols in the file:

windows: \n

linux, unix: \r\n

Javascript removes carriage return and line feed Symbol

response = response.replace(/\r|\n/ig,"");

Line terminator: A line terminator is a sequence of one or two characters that marks the end of a line for a sequence of input characters. The following codes are recognized as line terminators:

New line (line feed) character ('\n'),

followed by a carriage return character ("\r\n" "),

Separate carriage return character ('\r'),

Next line character ('\u0085'),

line separator ('\u2028 ') or

paragraph separator ('\u2029).

Therefore, considering the line ending symbol and its escaped form, the most guaranteed method is

str.replaceAll("(\n|\r|(\r\n)|(\u0085)|(\u2028)|(\u2029))", "")

[Recommended learning: js basic tutorial]

The above is the detailed content of How to remove carriage return in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:javascript how to printNext article:javascript how to print