trim·
Sunny-117 opened this issue · comments
正则写就可以
return str.replace(/(^\s+)|(\s+$)/g,'')//将前空格和后空格替换为空
function myTrim(str) {
return str.replace(/^\s+|\s+$/g, '');
}
String.prototype.myTrim = function() {
return this.replace(/(^\s+) | (\s+$)/g, "");
}