R
rithish
I am trying to implement a String trim function as told in
http://jibbering.com/faq/#FAQ4_16
I must be doing something wrong as I am unable to trim a given string.
Below is the test code. I am on IE6. Can someone point out to where I
am going wrong? Your help is appreciated.
[...snippet...]
<HTML>
<HEAD>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
if ( typeof String.prototype.trim == "undefined" ) {
String.prototype.trim = new Function("return
this.replace(/^\\s+|\\s+$/g,'')") }
function TestStringTrim ()
{
var trim_str = ' string ';
trim_str.trim();
alert ( 'after executing trim : ' + trim_str.length );
}
</SCRIPT>
</HEAD>
<BODY>
<FORM ID='frmTestJs' NAME='frmTestJs'>
<INPUT TYPE='BUTTON' ID='btnTest' NAME='btnTest' VALUE='Test Trim'
onClick='javascript:TestStringTrim();'>
</FORM>
</BODY>
</HTML>
[.../snippet...]
Regards,
Rithish.
http://jibbering.com/faq/#FAQ4_16
I must be doing something wrong as I am unable to trim a given string.
Below is the test code. I am on IE6. Can someone point out to where I
am going wrong? Your help is appreciated.
[...snippet...]
<HTML>
<HEAD>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
if ( typeof String.prototype.trim == "undefined" ) {
String.prototype.trim = new Function("return
this.replace(/^\\s+|\\s+$/g,'')") }
function TestStringTrim ()
{
var trim_str = ' string ';
trim_str.trim();
alert ( 'after executing trim : ' + trim_str.length );
}
</SCRIPT>
</HEAD>
<BODY>
<FORM ID='frmTestJs' NAME='frmTestJs'>
<INPUT TYPE='BUTTON' ID='btnTest' NAME='btnTest' VALUE='Test Trim'
onClick='javascript:TestStringTrim();'>
</FORM>
</BODY>
</HTML>
[.../snippet...]
Regards,
Rithish.