//执行多重连接
String.prototype.multiply=function(repeate){
let ret='';
for(let k=0;k<=repeate-1;k++){
ret+=this;
}
return ret;
}
//'abc'.multiply(3);//'abcabcabc'
//用于将字符串居中,并使用指定字符在左侧和右侧进行填充
String.prototype.center=function(width,fillchar){
let ret='';
for(let k=0;k<=width-1;k++){
ret+=fillchar;
}
ret+=this;
for(let k=0;k<=width-1;k++){
ret+=fillchar;
}
return ret;
}
//'abc'.center(5,'*');//'*****abc*****'
//将字符串的第一个字母转换为大写
String.prototype.capitalize=function(){
return this.length>1 ? this[0].toUpperCase() + this.substr(1,this.length-1) : this[0].toUpperCase();
}
//'abc'.capitalize();//'Abc'
//将字符串的每个单词的第一个字母转换为大写
String.prototype.title=function(){
let ret=this;
ret = ret.replace(/\s+/g, ' ');
arr = ret.split(' ');
ret='';
for(let k=0;k<arr.length;k++){
ret+=arr[k].capitalize() + ' ';
}
return ret.trim();
}
//"hello world javascript".title();//'Hello World Javascript'
//移除开头或结尾处的特定字符
String.prototype.strip=function(fix){
var str = this;
return (str.replace(new RegExp(fix + "$"), "")).replace(new RegExp("^" + fix), "");
}
//'ashok arunooba'.strip('a');//'shok arunoob'