javascript how to remove empty lines in string

王林
Release: 2021-10-27 16:47:19
Original
4300 people have browsed it

Javascript method to delete empty lines in a string: combine regular expressions to delete, such as [replace(/(\n[\s\t]*\r*\n)/g, '\ n').replace(/^[\n\r\n\t]*|[\n\r\n\t]*$/g, '');...].

javascript how to remove empty lines in string

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

We can use regular expressions to achieve this. Let’s take a look at the specific implementation code:

String.prototype.removeBlankLines = function () { return this.replace(/(\n[\s\t]*\r*\n)/g, '\n').replace(/^[\n\r\n\t]*|[\n\r\n\t]*$/g, '') }
Copy after login

Running results:

javascript how to remove empty lines in string

Recommended Learn:javascript video tutorial

The above is the detailed content of javascript how to remove empty lines in string. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!