-1

I want to search a function can replace all "?" in a string with an array position by position like below syntax:

replace("WHERE id > ? AND id < ?",[10, 20]);

with output will be:

"WHERE id > 10 AND id < 20"
vietean
  • 2,975
  • 9
  • 40
  • 65
  • Okay. When you have tried coding it and run into a [*specific* programming problem](http://stackoverflow.com/help/on-topic), come back and ask that question. More in the [tour], the [help], and [*How do I ask a good question?*](/help/how-to-ask) – T.J. Crowder Jun 21 '15 at 13:15
  • @T.J. Crowder: Thank you so much. – vietean Jun 21 '15 at 13:17

1 Answers1

0

I think it is same as this link

Replace multiple strings at once

    var find = "WHERE id > $ AND id < $"; 
    var replace = [10, 20] ;
 String.prototype.replaceArray = function(find, replace) {
      var replaceString = this;
      var regex; 
      for (var i = 0; i < find.length; i++) {
        regex = new RegExp(find[i], "$");
        replaceString = replaceString.replace(regex, replace[i]);
      }
      return replaceString;
    };
Community
  • 1
  • 1