• js简单函数封装


    //每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;
    
    
              }
     
  • 相关阅读:
    实验室资质认定评审准则和要素及要点
    如何进行内审?
    实验室比对结果评价的3种方法
    第一次如何申请CNAS实验室认可资质
    风险评估的实施步骤
    Servlet
    CMMI_SCAMPY评估方法
    PHP_2
    PHP_1
    java中String与StringBuilder的区别
  • 原文地址:https://www.cnblogs.com/hy928302776/p/6955441.html
Copyright © 2020-2023  润新知