Return to Snippet

Revision: 19887
at November 3, 2009 04:36 by Mithun


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

Initial URL
http://www.somacon.com/p355.php

Initial Description
his set of Javascript functions trim or remove whitespace from the ends of strings. These functions can be stand-alone or attached as methods of the String object. They can left trim, right trim, or trim from both sides of the string. Rather than using a clumsy loop, they use simple, elegant regular expressions.

Initial Title
Javascript Trim LTrim and RTrim Functions

Initial Tags
javascript

Initial Language
JavaScript