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

How to remove carriage return in javascript

藏色散人
藏色散人Original
2021-11-09 14:22:252722browse

How to remove carriage returns in javascript: 1. Create an HTML file; 2. Add a script tag; 3. Create a str variable; 4. Pass "str.replace(/[\r\n]/g ,"");" Just remove the carriage return.

How to remove carriage return in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript How to remove carriage return?

js removes the spaces in the string, carriage return and line feed

For example, the following json string,

The \n in the middle represents a line feed

var str = "{' retmsg':'success ',\n' trans_date':' 20170906'}";
console.log(str);
//"{' retmsg':'success ', //' trans_date':' 20170906'}"
//去掉空格 str = str.replace(/\ +/g,"");
console.log(str);
//"{'retmsg':'success', //'trans_date':'20170906'}"
//去掉回车换行 str = str.replace(/[\r\n]/g,"");
console.log(str);
//"{'retmsg':'success','trans_date':'20170906'}"

Recommended Study: "javascript 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