Posted By

rmariuzzo on 08/10/10


Tagged

javascript format text message


Versions (?)

Format a string with an array of arguments


 / Published in: JavaScript
 

URL: http://mariuzzo.com/

  1. /**
  2.  * Format a string with an array of arguments.
  3.  *
  4.  * @param msg A string.
  5.  * @return A formatted string
  6.  */
  7. function format(msg) {
  8. if (arguments && arguments.length > 1) {
  9. for (var i = 1; i < arguments.length; i++) {
  10. msg = msg.replace('{'+(i-1)+'}', arguments[i]);
  11. }
  12. }
  13. return msg;
  14. }

Report this snippet  

You need to login to post a comment.