JS中去除空格的方法(正则表达式)

JS中去除空格的方法有很多种这里只介绍正则表达式

replace(/(^\s*)|(\s*$)/g, "")
replace(/(^\s*)/g, "")
replace(/(\s*$)/g, "")

java代码中去空格使用str.trim()不管用时,可以使用str.replace(" ", ""); 去掉所有空格,包括首尾、中间  

猜你喜欢

转载自blog.csdn.net/cxfjava/article/details/84345090