Return to Snippet

Revision: 15707
at July 14, 2009 08:13 by neal_grosskopf


Updated Code
<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>

Revision: 15706
at July 14, 2009 08:13 by neal_grosskopf


Initial Code
<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.", ["NEAL", "GROSSKOPF"]));
</script>

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

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

Initial Title
Emulate ASP.NET's AppendFormat Method In Javascript

Initial Tags
javascript

Initial Language
JavaScript