How to Remove special characters at the end and at the begging of the string : <p>I have a string:</p>

<pre><code>String str = "    line0\n" +
                "line1\n" +
                "line2    line0\n" +
                "line3\n" +
                "line4   \n"
</code></pre>

<p>How can I get the following script:</p>

<pre><code>String formatedStr = "line0\n" +
                    "line1\n" +
                    "line2    line0\n" +
                    "line3\n" +
                    "line4"
</code></pre>
