Path: g2news1.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 12 Feb 2009 17:59:51 -0600 From: "Richard Cornford" Newsgroups: comp.lang.javascript References: <791914616252056809.637407rgqld-iinet.net.au@news.sunsite.dk> <4956b1a5$0$9375$ba4acef3@news.orange.fr> Subject: Re: String trim (was JavaScript Functions) Date: Thu, 12 Feb 2009 23:59:49 -0000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.3959 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3959 Message-ID: Lines: 235 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-zxCqxwzoQ2VKv3FHs1BY4Jx0SV0WUXRVhEBEKQnGNd8SOR/Y+hv2xqBDMs2LK3j4SWuRgElQlUbF3sx!HaOXJHQ63LHub2UqAKB+yeJsatpttx0k53vfrTQSh0PkQqnTbpFCQwICNO8KMIuXB3XX/zjIdEw= X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 kangax wrote: > Garrett Smith wrote: > [...] >> Is this fixed in recent JScript in IE8? > > I'll check this later, will let you know. If that question was whether \s in a regular expression matches '\u00A0' in IE 8 then it appears that the answer is no. >> Question: Why not:- >> >> function trimString(s){ >> return s.replace(/^[\s|\xA0]+|[\s|\xA0]+$/g, ''); >> } > > That would work, sure. By "work" I assume you mean that it corrects the fact that some javascript engines do not match '\u00A0' (the non-breaking space character) when \s is used in a regular expression. But is this an attempt to create methods that conform to the ECMA (3rd Ed.) specification, and thus are consistent across platforms, or is it a desire to arbitrarily include the non-breaking space in the set of matched characters for a trim function. The former seems the more reasonable goal, but in that case this trim function still falls short as where '\u00A0' is not matched the odds are extremely good that '\u2003' (EM space), to name but one, is not matched either. So the above function will still produce inconsistent results between javascript engines. The ECMA spec wants \s to match javascript's whit space characters and it line terminator characters, but the definition of whitespace includes all of Unicode's Zs group, and JScript, for example, does not match the majority of those. Try this out:-

Richard.