Created
January 26, 2014 07:03
-
-
Save wangwen1220/8629541 to your computer and use it in GitHub Desktop.
JS: 去掉 String 中的多余空格 | trim
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
// 去掉 String 中的多余空格 | |
if (!String.prototype.trim) { | |
String.prototype.trim = function() { | |
return this.replace(/^\s+|\s+$/g, ''); | |
}; | |
} | |
// 用法 | |
var str = " some string "; | |
str.trim(); | |
// 输出 str = "some string" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment