Javascript String replaceEx(apples,bananas,index)

Description

Javascript String replaceEx(apples,bananas,index)


String.prototype.replaceEx=function(apples,bananas,index){
    var arrSubStr=this.split(apples);//[];
    var sYouNew="";
    for(var i=0;i<arrSubStr.length;i++){
        if(i==arrSubStr.length-1){
            sYouNew+=arrSubStr[i];//from   w ww.  j  a v a2 s.  co m
        }else if(i==index-1){
            sYouNew+=arrSubStr[i]+bananas;
        }
        else {
            sYouNew += arrSubStr[i] + apples;
        }
    }
    return sYouNew;

}



PreviousNext

Related