Javascript String allReplace(obj)

Description

Javascript String allReplace(obj)


function replace(x) {
  var text = String(x);

  var lines = text.split("\n");
  var returnedText="";

  for(i=0;i<lines.length;i++){
   returnedText += lines[i].toString().allReplace({'?': '?', '?': 'i', '?': '?', '?': '?','?': '?','?': 'I','?': 'g','?': 's', '???': '??','?': 'S'});
   returnedText += "\n";
  }//  www .  ja v a 2 s.c o  m

  return returnedText;
}

String.prototype.allReplace = function(obj) {
    var retStr = this;
    for (var x in obj) {
        retStr = retStr.replace(new RegExp(x, 'g'), obj[x]);
    }
    return retStr;
};

Javascript String allReplace(obj)

String.prototype.allReplace = function(obj) {
  var retStr = this;
  for (var x in obj) {
      retStr = retStr.replace(new RegExp(x, 'g'), obj[x]);
  }//from www .j a v  a2  s  .com
  return retStr;
};



PreviousNext

Related