标签:字符串 左右 prototype func string str ons replace span
//左空格
String.prototype.leftSpace = function(){
return this.replace(/^\s+/g,"")
}
//右空格
String.prototype.rightSpace = function(){
return this.replace(/\s+$/g,"");
}
//全部空格
String.prototype.allSpace = function(){
return this.replace(/\s+/g,"");
}
//左右空格
String.prototype.rlSpace = function(){
return this.replace(/(^\s+)||(\s+$)/g,"")
}
var str = new String(‘ 1 2 3 5 4 ‘);
console.log(str.leftSpace());
console.log(str.rightSpace());
console.log(str.allSpace());
console.log(str.rlSpace());
标签:字符串 左右 prototype func string str ons replace span
原文地址:https://www.cnblogs.com/self-hard/p/10363169.html