Nodejs String Replace replaceAll( token, newToken, ignoreCase )

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

Method Source Code

// ----------------
String.prototype.replaceAll = function( token, newToken, ignoreCase ) {
    var _token;/* www .ja  va2s  .  c  o m*/
    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;
};

function safeTags(str) {
    return str.replaceAll('&','&amp;').replaceAll('<','&lt;').replaceAll('>','&gt;') ;
}

Related

  1. replaceAll
    ===
    
  2. replaceAll(
    String.prototype.replaceAll = function( 
      strTarget,
      strSubString
      ){
        var strText = this;
        var intIndexOfMatch = strText.indexOf( strTarget );
        while (intIndexOfMatch != -1)
          strText = strText.replace( strTarget, strSubString )
    ...
    
  3. replaceAll( searchStr, replaceStr )
    String.prototype.replaceAll = function( searchStr, replaceStr ) {
        var temp = this;
        while( temp.indexOf( searchStr ) != -1 ){
            temp = temp.replace( searchStr, replaceStr );
        return temp;
    
  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( 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(
    ...
    
  7. 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(
    ...
    
  8. replaceAll($oldText,$replaceText)
    String.prototype.replaceAll = function($oldText,$replaceText){
      return this.replace(new RegExp($oldText,"gm"),$replaceText);
    };