lcgyh / myDocs

0 stars 0 forks source link

怎么去除字符串空格? #15

Open lcgyh opened 7 years ago

lcgyh commented 7 years ago

怎么去除字符串空格?

lcgyh commented 7 years ago
  1. 去除所有空格:

str = str.replace(/\s+/g,"");

  1. 去除两头空格:

str = str.replace(/^\s+|\s+$/g,"");

  1. 去除左空格:

str=str.replace( /^\s*/, '');

  1. 去除右空格:

str=str.replace(/(\s*$)/g, "");