Web Hosting Talk







View Full Version : trim chars


hello20109876
05-08-2006, 02:04 AM
which java-script function can trim chars at left and right side of a string?

i.g.
original string: "\r hello \n\t ";
trimed string: "hello"

thx


.

Burhan
05-08-2006, 02:14 AM
<script>
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

var foo = ' hello ';
alert(foo);
alert(foo.trim());
</script>