Skip to content

Instantly share code, notes, and snippets.

@wangwen1220
Created January 26, 2014 07:03
Show Gist options
  • Save wangwen1220/8629541 to your computer and use it in GitHub Desktop.
Save wangwen1220/8629541 to your computer and use it in GitHub Desktop.
JS: 去掉 String 中的多余空格 | trim
// 去掉 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