Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #7372

Re: FAQ Topic - How do I trim whitespace? (2011-10-14)

From "J.R." <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: FAQ Topic - How do I trim whitespace? (2011-10-14)
Date 2011-10-13 22:09 -0300
Organization Aioe.org NNTP Server
Message-ID <j7824g$6lf$1@speranza.aioe.org> (permalink)
References <4e976d84$0$289$14726298@news.sunsite.dk>

Show all headers | View raw


On 13/10/2011 20:00, FAQ server wrote:
> -----------------------------------------------------------------------
> FAQ Topic - How do I trim whitespace?
> -----------------------------------------------------------------------
>
> ECMAScript 5 defines `String.prototype.trim`. Where not supported,
> it can be added as a function that uses a regular expression:
>
> if(!String.prototype.trim) {
> String.prototype.trim = function() {
> return String(this).replace(/^\s+|\s+$/g, "");
> };
> }

> The complete comp.lang.javascript FAQ is at
> http://jibbering.com/faq/
>

A few months ago, there was an article at Jibbering,com with a different 
version of this code:

   /** @see http://jibbering.com/faq/#trimString */
   if (typeof String.prototype.trim !== "function") {
     String.prototype.trim = function () {
       // return String(this).replace(/^\s+|\s+$/g, "");
       return this.replace(/^\s+|\s+$/g, "");
     };
   }

I think that is more consistent with ECMA-262 5th ed., 15.5.4.20.

-- 
Joao Rodrigues (J.R.)

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

FAQ Topic - How do I trim whitespace? (2011-10-14) "FAQ server" <javascript@dotinternet.be> - 2011-10-13 23:00 +0000
  Re: FAQ Topic - How do I trim whitespace? (2011-10-14) "J.R." <groups_jr-1@yahoo.com.br> - 2011-10-13 22:09 -0300
    Re: FAQ Topic - How do I trim whitespace? (2011-10-14) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-10-14 20:54 +0200
    Re: FAQ Topic - How do I trim whitespace? (2011-10-14) Dr J R Stockton <reply1141@merlyn.demon.co.uk> - 2011-10-15 19:17 +0100

csiph-web