Return a new string with any spaces trimmed the left and right of the string - Node.js String

Node.js examples for String:sub string

Description

Return a new string with any spaces trimmed the left and right of the string

Demo Code


/**//ww w .  java  2  s. c  o  m
 * Return a new string with any spaces trimmed the left and right of the string
 * @version 1.0.0
 * @date June 30, 2010
 * @package jquery-sparkle {@link http://www.balupton/projects/jquery-sparkle}
 * @author Benjamin "balupton" Lupton {@link http://www.balupton.com}
 * @copyright (c) 2009-2010 Benjamin Arthur Lupton {@link http://www.balupton.com}
 * @license GNU Affero General Public License version 3 {@link http://www.gnu.org/licenses/agpl-3.0.html}
 */
String.prototype.trim = String.prototype.trim || function() {
  // Trim off any whitespace from the front and back
  return this.replace(/^\s+|\s+$/g, '');
};

Related Tutorials