By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Writing a generic function to format strings using bob.js

P: 1
Hello,

Expand|Select|Wrap|Line Numbers
  1. var string = "My name is {0} and I am {1} years old."; 
  2. var result = bob.string.formatString(sFormat, "myname", 25);
I want to write a function such that I can pass the string with required number of arguments and it will return me the formatted string with all {0} , {1}, .. replaced by my passed arguments. Something like:

Expand|Select|Wrap|Line Numbers
  1. function test( string , argument1 , argument2 , ....){
  2.   return bob.string.formatString(sFormat, args);
  3. }
Apr 14 '16 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
Template Literals (https://developer.mozilla.org/en-US/...plate_literals) look quite close otherwise you’d have to use String.replace().
Apr 14 '16 #2

Post your reply

Sign in to post your reply or Sign up for a free account.