Skip to content

Instantly share code, notes, and snippets.

@simplelife7
Created July 1, 2013 15:55
Show Gist options
  • Save simplelife7/5902092 to your computer and use it in GitHub Desktop.
Save simplelife7/5902092 to your computer and use it in GitHub Desktop.
【JS】去除字符串空格
// 功能: 1)去除字符串前后所有空格
// 2)去除字符串中所有空格(包括中间空格,需要设置第2个参数为:g)
function Trim(str,is_global)
{
var result;
result = str.replace(/(^\s+)|(\s+$)/g,"");
if(is_global.toLowerCase()=="g")
result = result.replace(/\s/g,"");
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment