Javascript String ReplaceAll(stringToFind, stringToReplace)

Description

Javascript String ReplaceAll(stringToFind, stringToReplace)



String.prototype.ReplaceAll = function (stringToFind, stringToReplace) {

    var temp = this;

    var index = temp.indexOf(stringToFind);

    while (index != -1) {

        temp = temp.replace(stringToFind, stringToReplace);

        index = temp.indexOf(stringToFind);

    }/*from w w w .  j a v  a 2 s. c  o m*/

    return temp;

}



PreviousNext

Related