/ Published in: JavaScript

Learn how to emulate ASP.NET's AppendFormat method in Javascript. AppendFormat is essentially a simple form of concatenation in ASP.NET.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> function AppendFormat(input,arr) { for (i = 0; i < arr.length; i++) { while (input.indexOf("{"+i+"}") != -1) { input = input.replace("{"+i+"}", arr[i]); } } return input; } document.write(AppendFormat("Lorem ipsum dolor sit {0} {1} amet, consectetur {0} adipiscing {0} elit.", ["TEST", "TEST2"])); </script>
URL: http://www.nealgrosskopf.com/tech/thread.asp?pid=54
Comments
