title: To display long text area comments in a webpage
body: <p>I have a long text area comment given as input by user. In order that it should be properly wrapped in my JSP, I'm using the below code. <code>commentarea</code> is my text area:</p>
  
  <pre><code>function addNewlines(commentarea) {
  
    var result = '';
    while ($.trim(commentarea).length &gt; 0) {
      result += $.trim(commentarea).replace(/[\s\n\r]+/g, ' ').substring(0, 40) + '\n'; commentarea= $.trim(commentarea).replace(/[\s\n\r]+/g, ' ').substring(40);
    }
    return result;
  }
  </code></pre>
  
  <p>The text is getting wrapped but the problem is I'm getting white spaces between words that are at 40 character length. For example, in my output I'm getting a space between 
  <code>prog rammable</code> and <code>sim ple</code></p>
  
  <pre><code>hello world today this is a simple prog rammable hello world today this is a sim ple prog rammable
  </code></pre>