Discover javascript strip whitespace, include the articles, news, trends, analysis and practical advice about javascript strip whitespace on alibabacloud.com
Achieve 1
Copy Code code as follows:
String.prototype.trim = function () {
return this. Replace (/^\s\s*/, '). Replace (/\s\s*$/, ');
}
It does not look very good, using two of regular replacements, the actual speed is
A set of methods for removing spaces in JavaScript. The script home has previously released a lot of code for removing spaces, which is more comprehensive. Implementation 1
The Code is as follows:
String. prototype. trim = function (){Return this.
The people's brains were kicked by the donkey until javascript1.8.1 support the Trim function (and trimleft,trimright), but now only firefox3.5 support. Because it is too often used to remove whitespace on both sides of a string, each large class
JavaScript Regular Expressions1. Using the JS regular expression, first of all to understand the JS regular expressions commonly used symbols, such as:
/.../
Represents the beginning and end of a pattern
^
Match
The W3C team's head was kicked off until javascript1.8.1 supported the trim function (with trimleft and trimright). Unfortunately, only firefox3.5 supported it now. Since the blank spaces on both sides of the string are too common, all major types
Core code:Copy codeThe Code is as follows:/*** Jscript. string package* This package contains utility functions for working with strings.*/If (typeof jscript = 'undefined '){Jscript = function (){}}Jscript. string = function (){}/*** This function
Accounting. js is a very small JavaScript repository used to format numbers, amounts, and currencies. Optional Excel Style column rendering is provided. It does not depend on any JS framework. You can customize the code content and
The accounting.
Because of the previous version of JavaScript 1.8.1, there is no built-in trim function, so JQuery has its own implementation. In different versions of jquery, the TRIM function is implemented differently.Read this article to master the use of
IntroducedThe GCC (Google Closure Compiler) is a JS code compression compilation tool released by Google. It can parse the JS code, remove the unwanted code (dead), and rewrite it, and then compress.Three types of compression modesGCC offers three
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.