自己写了个javascript中不采用正则表达式的replace函数的

function replaceX(strMaster,strA,strB)
{
    var startIndex,lengthA,firstPart,lastPart,resultPart;
    startIndex=strMaster.indexOf(strA);
    if (startIndex>=0)
    {
        firstPart=strMaster.substr(0,startIndex);
        lengthA=strA.length;
        lastPart=strMaster.substr(startIndex+lengthA,strMaster.length-(startIndex+lengthA)+1);
        resultPart=firstPart+strB+lastPart;
        startIndex=resultPart.indexOf(strA);
        if(startIndex>=0)
        {
            return replaceX(resultPart,strA,strB);
        }
        else
        {
            return resultPart;
        }
    }
    else
    {
        return strMaster;
    }
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭