0

I know this question has been asked before, but other questions I saw were 5 years old. How can I format a string like this in modern Javascript ?

var x = str('My name is %x %y', 'john', 'walker');
dimitris93
  • 4,155
  • 11
  • 50
  • 86
  • That linked duplicate is *more* than 5 years old. – Pointy Apr 13 '16 at 14:17
  • [Some documentation on "modern" JavaScript approaches.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) – Pointy Apr 13 '16 at 14:17
  • http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format Has newer answers including template formate from ES6 – scrappedcola Apr 13 '16 at 14:19
  • Even a 40 years old well-written script can nicely do this. You don't need anything "modern" for manipulating strings. – Ram Apr 13 '16 at 14:19
  • @Vohuman ES2015 has a feature explicitly for this purpose (template literals). – Pointy Apr 13 '16 at 14:20
  • Yes, I know that feature. The point was something else man. – Ram Apr 13 '16 at 14:21
  • The system works by new answers being posted for old questions whenever new techniques become available, [just like in this case](http://stackoverflow.com/a/24850933/502381). It's not reasonable to post duplicate questions asking for new solutions every couple of years. – JJJ Apr 13 '16 at 14:22
  • 2
    @Juhana agreed of course. Venerable old questions and their venerable old answers are fine, but nothing clearly directs new users to scroll down looking for new answers describing new facilities stuck at the bottom with scant upvotes. – Pointy Apr 13 '16 at 14:27
  • 2
    (I acknowledge that in this case the template answer is #2 on the page.) – Pointy Apr 13 '16 at 14:28

0 Answers0