//每index个字符插入一个str字符串

String.prototype.insertStrPerIndex =function(index,str){

if(this.length>index&&index>0){
var arr = new Array();
var num = parseInt(this.length/index);
console.log(num);
for(var i=0;i<=num;i++){
var firstval =i*index;
if(firstval<this.length){
arr.push(this.substr(firstval,index));
}
}
return arr.join(str);
}else{
return this.toString();
}
}

//去掉字符串两端的空白

String.prototype.trim = function() {
return this.replace(/(^\s+)|(\s+$)/g, "");
}

//构建Stringbuffer

function StringBuffer(){ 
this.content = new Array; 
} 
StringBuffer.prototype.append = function( str ){ 
this.content.push( str ); 
} 
StringBuffer.prototype.toString = function(){ 
return this.content.join(""); 
}

 //去掉所有的空格、table

String.prototype.trimAll = function() {
    return this.replace(/\s/g,"")
}

 //重写replaceAll

String.prototype.replaceAll =function(oldWord,newWord){
        var res =this;
    var mid ="";
        while((mid=res.replace(oldWord,newWord))!=res){
            res =mid;
        }
        return res;
    }

 //判断是否是中文


 function ischinese(s){

              var ret=true;

              for(var i=0;i<s.length;i++)

              ret=ret && (s.charCodeAt(i)>=10000);

              return ret;

          }
 

 

相关文章:

  • 2022-12-23
  • 2021-08-27
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-10-14
相关资源
相似解决方案