Get the data from the server using the regular expression of JS to space _javascript tips
Source: Internet
Author: User
I've been having a stupid question this morning, and I haven't found it.
If $str= "";
$STR = "$str-$sno";
So down, $str front will have a space, JS get this value, you must remove the space
Go to the Space function Rstr=rstr.replace (/(^\s*) | ( \s*$)/g, "");
Other:
Go to left space replace (/(^\s*)/g, "");
Go to right space replace (/(\s*$)/g, "");
In addition, if you do a step-by-step check of the program flow, stop at if, you must output two values in the IF, compare, or add a # to see if there are spaces
To sum up
1, where the string is connected to the place, may produce spaces, and then split the time, it appeared with the original do not want to wait, therefore, must be removed before and after the space
2, especially in obtaining data from the server, JS must pay attention to the occurrence of the space may
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.