HTML View<script>
<!--
function trim(text) {
for (var first_nonwhite = 0; first_nonwhite < text.length && (text[first_nonwhite] == ' ' || text[first_nonwhite] == '\t' || text[first_nonwhite] == '\n' || text[first_nonwhite] == '\r'); first_nonwhite++);
for (last_nonwhite = text.length-1; last_nonwhite > first_nonwhite && (text[last_nonwhite] == ' ' || text[last_nonwhite] == '\t' || text[last_nonwhite] == '\n' || text[last_nonwhite] == '\r'); last_nonwhite--);
return text.substring(first_nonwhite, last_nonwhite+1);
}
-->
</script>
<textarea id="textarea" rows="10" cols="70">
Enter some
text
containing whitespace into this box. Click the button and
only whitespace
at the end and the beginning will be stripped.
</textarea>
<input type="button" onclick="document.getElementById('textarea').value = trim(document.getElementById('textarea').value);" value="trim" />