Created
July 1, 2013 15:55
-
-
Save simplelife7/5902092 to your computer and use it in GitHub Desktop.
【JS】去除字符串空格
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 功能: 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