Replace space in string and test - Node.js String

Node.js examples for String:Replace

Description

Replace space in string and test

Demo Code

String.prototype.replaceSpaces = function() {
  var length = this.length;
  for(var i = 0; i < length; i++) {
    if(this[i] == ' ') {
      this[i] = "%20"
    }/*from   w ww .  j av  a  2 s  .c  o  m*/
  }
  return this.toString();
}


console.log("This is my Name".replace(/ /ig, '%20'));

Related Tutorials