While working with string in javascript sometimes we need to remove whitespace from the beginning and end of a string. Just do something like this:
String.prototype.trim=function(){ return this.replace(/^\s*|\s*$/g,”); } String.prototype.ltrim=function(){ return this.replace(/^\s*/g,”); } String.prototype.rtrim=function(){ return this.replace(/\s*$/g,”); }
How to use:
var myString = ‘ mystring ‘;
sTrim=myString.trim(); //return ‘mystring’
sLTrim=myString.ltrim(); //return ‘mystring ‘
sRTrim=myString.rtrim(); //return ‘ mystring’
There are some sample javascript codes to refer:
http://www.hibuddyz.com/forum/