Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This seems to do the trick:</p> <pre><code>String.prototype.format = -&gt; args = arguments return this.replace /{(\d+)}/g, (match, number) -&gt; return if typeof args[number] isnt 'undefined' then args[number] else match </code></pre> <p>Translated using some <a href="https://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format">javascript from fearphage</a></p> <p>Which can then be used like this:</p> <pre><code>fmt = "&lt;p&gt;{0} {1} (&lt;a href='mailto:{2}'&gt;{2}&lt;/a&gt;)&lt;/p&gt;" mystring = fmt.format "Fred", "Flinstone", "fflinstone@bedrock.gov" </code></pre> <p>mystring would then be:</p> <pre><code>&lt;p&gt;Fred Flinstone (&lt;a href='mailto:fflinstone@bedrock.gov'&gt;fflinstone@bedrock.gov&lt;/a&gt;)&lt;/p&gt; </code></pre> <p>Using the #{var} approach (while perfect for example given) doesn't work with a string that needs to be recycled several times. In a looping situation for example:</p> <pre><code> HTML_header = fs.readFileSync('includes/notify/header.html').toString() HTML_managerOpen = fs.readFileSync('includes/notify/managerOpen.html').toString() HTML_student = fs.readFileSync('includes/notify/student.html').toString() HTML_managerClose = fs.readFileSync('includes/notify/managerClose.html').toString() HTML_footer = fs.readFileSync('includes/notify/footer.html').toString() HTML_final = HTML_header getter2 = (r, callback) -&gt; HTML_final += HTML_managerOpen.format r.EMAIL, r.FNAME, r.LNAME, r.STUDENTS.length, r.PHONE, r.MEMAIL, r.MFNAME, r.MLNAME async.forEachSeries r.STUDENTS, getter3, (err) -&gt; HTML_final += HTML_managerClose callback null getter3 = (r, callback) -&gt; HTML_final += HTML_student.format r.EMAIL, r.FNAME, r.LNAME, r.PHONE, r.DESCRIPTION, r.ENROLLED, "", "", "", "", "", "", r.CERTEXAMSCORE, r.COIKEY callback null async.forEachSeries results, getter2, (err) -&gt; cback null, HTML_final + HTML_footer </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload