Home  >  Article  >  Web Front-end  >  Get the data sent from the server and use JS to remove spaces using regular expressions_javascript skills

Get the data sent from the server and use JS to remove spaces using regular expressions_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:54:531177browse

Until now this morning, I have been working on a very stupid question, and I have never found it.
If $str="";
$str = "$str-$sno";

This way , there will be a space in front of $str. After js obtains this value, the space must be removed

to remove the space function rstr=rstr.replace(/(^s*)|(s*$)/g,"" );

Another:

replace the left space(/(^s*)/g, "");

replace(/(s*$) the right space )/g, "");

In addition, if you check the program flow step by step and stop at the if, you must output the two values ​​​​in the if at the same time for comparison, or add in front Go to # to see if there are spaces

To summarize

1. Wherever strings are used to connect, spaces may be generated. When split, there will be spaces that are different from the original ones. situation, therefore, be sure to remove the leading and trailing spaces

2. Especially when obtaining data from the server, JS must pay attention to the possibility of spaces.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn