1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3 <head>
4  <title>Sprintf demo</title>
5  <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
6 </head>
7 <body>
8  <h3>Demo of the <em>Sprintf method</em> from the
9  <a href="http://debugger.ru/projects/browserextensions/string" >String extensions</a></h3>
10  <hr />
11  <table width="100%">
12   <tr>
13    <td>
14     String in the <a href="http://perldoc.perl.org/functions/sprintf.html" target="_blank">Sprintf</a> format:<br />
15     <textarea id="test_s" type="text" style="height: 80px; width:95%" >The %1$s contains %0$d monkeys.
16That's a nice %1$s full of %0$d monkeys.</textarea>
17    </td>
18   </tr>
19   <tr>
20    <td>
21     Arguments, one per line:<br />
22     <textarea id="test_v" type="text" style="height: 80px; width:95%" >5
23tree</textarea>
24    </td>
25   </tr>
26   <tr>
27    <td>
28     Result:<br />
29     <textarea id="test_r" type="text" style="height: 80px; width:95%" ></textarea>
30    </td>
31   </tr>
32   <tr>
33    <td>
34     <input id="starts" type="button" value="Execute" />
35     <script src="../helpers.js" type="text/javascript"></script>
36     <script src="../objectextensions.js" type="text/javascript"></script>
37     <script src="../arrayextensions.js" type="text/javascript"></script>
38     <script src="../regexpextensions.js" type="text/javascript"></script>
39     <script src="../numberextensions.js" type="text/javascript"></script>
40     <script src="../stringextensions.js" type="text/javascript"></script>
41     <script type="text/javascript">
42       document.getElementById('starts').onclick = function() {
43         var ts = document.getElementById('test_s')
44            ,tv = document.getElementById('test_v')
45            ,tr = document.getElementById('test_r')
46            tr.value = ts.value.sprintf.apply(ts.value,tv.value.split(/\r?\n\r?/g));
47       }
48       document.getElementById('starts').click();
49     </script>
50    </td>
51   </tr>
52  </table>
53 </body>
54</html>