Examples of removing leading and trailing spaces in javascript_javascript skills
- WBOYOriginal
- 2016-05-16 17:16:53962browse
Code
function String.prototype.Trim() { return this.replace(/(^/s*)|(/s*$)/g, ""); } // Remove left and right spaces
function String.prototype.Ltrim() { return this.replace( /(^/s*)/g, ""); } // Remove the left space
function String.prototype.Rtrim() { return this.replace(/(/s*$)/g, "") ;} // Remove the right space
Example
Let’s take a look at what “/s means” in Js scripts.
s matches any whitespace character, including Spaces, tabs, form feeds, etc. Equivalent to [fnrtv].
Please remember that it is lowercase s
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