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, '');...].
#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, '') }
Running results:
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!