[Short article] Different blank characters lead to program execution failure

A blank character displayed on the screen has no difference to the programmer, but the completely different representation method at the bottom layer is very likely to cause the program to fail!

Today, the blogger encountered a problem of a space character. Probably the situation is that the front-end writes SQL and passes it in. Sometimes the back-end can execute it, and sometimes it cannot execute it. After reproduction and testing, the problem is finally found and solved. The specific process is not shown, we do a test to explore the impact of different characters on the program.

call interface
This is a parameter passed in when using PostMan to call the interface. You can see that although blank characters are displayed, the editor has intelligently prompted that there are differences between these two blank characters. Let's copy it to the IDEA printout for viewing.
IDEA view

Although the editor will display the code differently after copying the code to IDEA, it is completely indistinguishable to the naked eye from the output results. As a result, from the log, there is no problem with the SQL code and the parameters accepted by the backend, but the program cannot be executed.
abnormal problem

Solution: The Ascii code of NBSP is 160, we can replace it with a regular space according to this feature.
str1. replaceAll(String. valueOf((char) 160), " ");

Guess you like

Origin blog.csdn.net/qq_44491709/article/details/127748113