Can't get Javascript function to work in a demo
<pre><code>function trim(str,options){
  var   string = str.replace(/^\s\s*/, ''),
        ws = /\s/,
        i = str.length,
        j = -1;
  if(options==="begin"){while(ws.test(string.charAt(++j)));return string.slice(j,i);}
  if(options==="end"){while(ws.test(string.charAt(--i)));return string.slice(j+1,i+1);}
  while(ws.test(string.charAt(--i)));while(ws.test(string.charAt(++j)));
  return string.slice(j, i + 1);
}
</code></pre>

<p>This function is an implementation of the Trim() method that you find in C#.</p>

<p>I've added options for removing withspace both at the beginning and end. The problem is, I can't get it to work in a demo.</p>

<p>What I've done is this:</p>

<pre><code>var a = "           zareaerar  arzare        ";
var b = "aezze          azeze      a    ";
var c = "azrazza rzrzrzrp"
var d = " aezzaeazeazeaz         azez ";

document.write('&lt;p style="backround:#ff0000"&gt;',trim(a,"begin"),'&lt;/p&gt;','&lt;br /&gt;');
document.write('&lt;p style="backround:#ff0000"&gt;',trim(b,"begin"),'&lt;/p&gt;','&lt;br /&gt;');
document.write('&lt;p style="backround:#ff0000"&gt;',trim(c,"begin"),'&lt;/p&gt;','&lt;br /&gt;');
document.write('&lt;p style="backround:#ff0000"&gt;',trim(d,"begin"),'&lt;/p&gt;','&lt;br /&gt;');
</code></pre>

<p>First of all, no background-color appears and the strings also seem to loose the spaces in the middle of the string...</p>

<p>Does this work with user-input only? Are strings automatically trimmed these days?</p>
