Home > Web Front-end > JS Tutorial > Examples of removing leading and trailing spaces in javascript_javascript skills

Examples of removing leading and trailing spaces in javascript_javascript skills

WBOY
Release: 2016-05-16 17:16:53
Original
961 people have browsed it

Code
Copy code The code is as follows:

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
Copy code The code is as follows: 🎜>



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
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template