//每index個字符插入一個str字符串app
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(); } }
//去掉字符串兩端的空白this
String.prototype.trim = function() { return this.replace(/(^\s+)|(\s+$)/g, ""); }
//構建Stringbufferspa
function StringBuffer(){ this.content = new Array; } StringBuffer.prototype.append = function( str ){ this.content.push( str ); } StringBuffer.prototype.toString = function(){ return this.content.join(""); }
//去掉全部的空格、tableprototype
String.prototype.trimAll = function() { return this.replace(/\s/g,"") }
//重寫replaceAllcode
String.prototype.replaceAll =function(oldWord,newWord){ var res =this; var mid =""; while((mid=res.replace(oldWord,newWord))!=res){ res =mid; } return res; }
//判斷是不是中文blog