DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Javacript Trim A String
removes all leading and trailing spaces from string
str.replace(/^\s*/, "").replace(/\s*$/, "");
alternative, extend the string class
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }






Comments
Snippets Manager replied on Mon, 2009/04/13 - 3:10pm