4-Aug-03 (Created: 4-Aug-03) | More in 'CS-JavaScript'

How to create a trim function for a string

String.prototype.trim = function() {

// skip leading and trailing whitespace
// and return everything in between
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}