title: How can I insert a character after every n characters in javascript?
body: <p>I have a string:
  <em>&quot;The quick brown fox jumps over the lazy dogs.&quot;</em></p>
  <p>I want to use JavaScript (possibly with jQuery) to insert a character every <em>n</em> characters.  For example I want to call:</p>
  <pre><code>var s = &quot;The quick brown fox jumps over the lazy dogs.&quot;;
  var new_s = UpdateString(&quot;$&quot;,5);
  // new_s should equal &quot;The q$uick $brown$ fox $jumps$ over$ the $lazy $dogs.$&quot;
  </code></pre>
  <p>The goal is to use this function to insert <a href="https://stackoverflow.com/questions/226464/soft-hyphen-in-html-wbr-vs">&amp;shy</a> into long strings to allow them to wrap.</p>
  <p>Maybe someone knows of a better way?</p>