JQuery trim to remove the end-end null character of the string implementation method description _jquery

Source: Internet
Author: User

If your project is using the JQuery framework, you will of course Choose: Jquery.trim (String) to remove the null characters from the end of the string. If you don't use jquery as a simple implementation. I have previously sent a small snippet of code: JavaScript to remove the string around the space-trim (), this write is relatively rough and to use the recursive operation. So many people are very dissatisfied with the quality of the code, including me.
Occasionally looked down the jquery code and found the very value of our learning.

See how it achieves this function, the code has only one sentence: Use the regular method.

JavaScript Trim Implementation Code
function Trim (text) {
Return (text | | ""). Replace (/^/s+|/s+$/g, "");
}

If you don't use jquery or other frameworks in your project, you can copy the code with this feature. believe that the structure and quality of the code will be another you satisfied.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.