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

Writing a generic function to format strings using bob.js

P: 1

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

Expert Mod 5K+
P: 8,639
Template 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.