JS: Remove space between the left and right sides of the string

Source: Internet
Author: User

White space characters

  • In JavaScript's regular, the \s is Unicode-aware, can match \u0020, \u0009 and so on white space character. However, the implementation of each browser is different, see also: JavaScript, Regex, and Unicode.
  • In most cases, the JS class Library uses/^\s+|\s+$/g when implementing the Trim method.
  • In JQuery, the detection of \U00A0 was added:/^ (\s|\u00a0) +| (\S|\U00A0) +$/g\u00a0 is actually   Represents non-breaking space (uninterrupted space)

 

  • Strictly semantically, usage scenarios are not expected to be used when auto-wrapping. But in reality, most of the cases,  is used to denote pure spaces. Because more than one word spaces in the HTML will be treated as a space, in order to continuously output multiple spaces, had to use   It is argued that multiple & #32 are used; outputting multiple spaces is the best choice, but the powerful HTML engine will still put multiple & #32; Converted into one.

JS: Remove space between the left and right sides of the string

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.