The small problem of empty, small problem also noisy. Record the

Source: Internet
Author: User

1 problem Origin: made a commodity management system. The product name only uses trim to remove the leading and trailing blanks. (Of course, the framework comes with a variety of anti-SQL anti-X functions, which is not the focus) the product name format is as follows: REPLAY women's down jacket 23803

The product name is pretty good. Here's the problem. When searching because there is no going to the middle space. Cause if the middle of the product name is a double space. Can not search out. Negligence of work. Used to write "published article" Such a function is reluctant to go to space (blank).

2 Debugging Road: Found in the browser single space is replaced by a single +, double space replaced by + +. The system has been customer service sister input a lot of products. Tangled.

3 Problem derivation: Just note that some functions can not filter Chinese full-width space on the line.

4 Solution: PHP:

$str = ' REPLAY ladies down jacket 23803 ';

$str =preg_replace ("/\s| /"," ", $str);

Echo $str;

Java:

         String str = ' REPLAY ladies down jacket 23803 '; With tabs with Chinese full-width spaces

String str2 = str.replace ((char) 12288, ');

String STR3 = Str2.replaceall ("\\s*|\t|\r|\n", "" ");
System.out.println (STR3);

Can be ligatures. Separate writing is a way of showing ideas.


      

The small problem of empty, small problem also noisy. Record the

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.