A fusion of technology, music, and geekyness.

Quick and Dirty trim() in Javascript

Shailesh N. Humbad had some really quick, simple, and useful code snippets on their website on how to provide trim() functionality (like PHP’s trim) in Javascript. Check out his Javascript Trim LTrim and RTrim Functions. My favorite application of his examples is as follows:

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}		

trimmedString = string.trim();

Thanks for your work on this Shailesh. You made my life easier :)

Leave a Reply

Powered by Wordpress | Designed by Elegant Themes