Posted By

neal_grosskopf on 07/14/09


Tagged

javascript


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

neal_grosskopf


Emulate ASP.NET's AppendFormat Method In Javascript


 / Published in: JavaScript
 

URL: http://www.nealgrosskopf.com/tech/thread.asp?pid=54

Learn how to emulate ASP.NET's AppendFormat method in Javascript. AppendFormat is essentially a simple form of concatenation in ASP.NET.

  1. <script type="text/javascript">
  2. function AppendFormat(input,arr)
  3. {
  4. for (i = 0; i < arr.length; i++)
  5. {
  6. while (input.indexOf("{"+i+"}") != -1)
  7. {
  8. input = input.replace("{"+i+"}", arr[i]);
  9. }
  10. }
  11. return input;
  12. }
  13.  
  14. document.write(AppendFormat("Lorem ipsum dolor sit {0} {1} amet, consectetur {0} adipiscing {0} elit.", ["TEST", "TEST2"]));
  15. </script>

Report this snippet  

You need to login to post a comment.