Nodejs String Replace replaceAll( token, newToken, ignoreCase )

Here you can find the source of replaceAll( token, newToken, ignoreCase )

Method Source Code

/**//ww  w.j a va2 s . co  m
 * ReplaceAll by Fagner Brack (MIT Licensed)
 * Replaces all occurrences of a substring in a string
 */
String.prototype.replaceAll = function( token, newToken, ignoreCase ) {
    var _token;
    var str = this + "";
    var i = -1;

    if ( typeof token === "string" ) {

        if ( ignoreCase ) {

            _token = token.toLowerCase();

            while( (
                i = str.toLowerCase().indexOf(
                    token, i >= 0 ? i + newToken.length : 0
                ) ) !== -1
            ) {
                str = str.substring( 0, i ) +
                    newToken +
                    str.substring( i + token.length );
            }

        } else {
            return this.split( token ).join( newToken );
        }

    }
return str;
};

Related

  1. replaceAll( searchStr, replaceStr )
    String.prototype.replaceAll = function( searchStr, replaceStr ) {
        var temp = this;
        while( temp.indexOf( searchStr ) != -1 ){
            temp = temp.replace( searchStr, replaceStr );
        return temp;
    
  2. replaceAll( token, newToken, ignoreCase )
    String.prototype.replaceAll = function( token, newToken, ignoreCase ) {
        var _token;
        var str = this + "";
        var i = -1;
        if ( typeof token === "string" ) {
            if ( ignoreCase ) {
                _token = token.toLowerCase();
                while( (
                    i = str.toLowerCase().indexOf(
    ...
    
  3. replaceAll( token, newToken, ignoreCase )
    String.prototype.replaceAll = function( token, newToken, ignoreCase ) {
        var _token;
        var str = this + "";
        var i = -1;
        if ( typeof token === "string" ) {
            if ( ignoreCase ) {
                _token = token.toLowerCase();
                while( (
                    i = str.toLowerCase().indexOf(
    ...
    
  4. replaceAll( token, newToken, ignoreCase )
    String.prototype.replaceAll = function( token, newToken, ignoreCase ) {
        var _token;
        var str = this + "";
        var i = -1;
        if ( typeof token === "string" ) {
            if ( ignoreCase ) {
                _token = token.toLowerCase();
                while( (
                    i = str.toLowerCase().indexOf(
    ...
    
  5. replaceAll( token, newToken, ignoreCase )
    String.prototype.replaceAll = function( token, newToken, ignoreCase ) {
        var _token;
        var str = this + "";
        var i = -1;
        if ( typeof token === "string" ) {
            if ( ignoreCase ) {
                _token = token.toLowerCase();
                while( (
                    i = str.toLowerCase().indexOf(
    ...
    
  6. replaceAll($oldText,$replaceText)
    String.prototype.replaceAll = function($oldText,$replaceText){
      return this.replace(new RegExp($oldText,"gm"),$replaceText);
    };
    
  7. replaceAll()
    String.prototype.replaceAll = function() {
        var target = this;
        return target.split(" ").join("-");
    };
    String.prototype.numberToString = function() {
        var target = this;
        var storing = "";
        var strlength = target.length;
        var numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
    ...
    
  8. replaceAll(AFindText, ARepText)
    String.prototype.replaceAll = function(AFindText, ARepText) {
        var raRegExp = new RegExp(AFindText, "g");
        return this.replace(raRegExp, ARepText);
    };
    
  9. replaceAll(AFindText, ARepText)
    String.prototype.replaceAll = function (AFindText, ARepText) {
        return this.replace(new RegExp(AFindText, "gm"), ARepText)
    };