Remove Special spaces

Source: Internet
Author: User

requirement : Remove all spaces in the string

Practice :

SYSTEM.OUT.PRINTLN ("Revised Guide". Replace ("", ""));

problem : The space between "Nan Xiu" cannot be removed

reason : "Nan Xiu" This string has a special space, the corresponding Unicode code is \u0026\u0023\u0031\u0036\u0030\u003b. The Unicode code corresponding to the normal space is "\u0020"

Here is the difference between the two spaces printed in Python:

In [1]: Print (' \u0026\u0023\u0031\u0036\u0030\u003b '. Encode (' UTF8 '))
B ' & #160; '

In [2]: Print (' \u0020 '. Encode (' UTF8 '))
B ' '

solutions with the help of a small partner :

Pattern p = pattern.compile ("[\\s*|\t|\r|\n|  \\p{zs}]* ");
Matcher m = P.matcher ("Guide Revision");
System.out.println (M.replaceall (""));

Remove Special spaces

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.