Wrox Programmer Forums
|
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers by Nicholas C. Zakas; ISBN: 9780764579080
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2006, 02:03 AM
Registered User
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default trim function on page 206

Hi,
On page 206, you provide a trim function to trim white space,
Code:
String.prototype.trim = function () {
var reExtraSpace = /^\s+(.*?)\s+$/;
return this.replace(reExtraSpace, "$1");
};
var sTest = "  this is a test  ";
alert("[" + sTest + "]"); //outputs ¡° [ this is a test ] ¡°
alert("[" + sTest.trim() + "]"); //outputs ¡° [this is a test]¡±
But if the being of string to be trimmed has no white space, like "this is a test ", the method can't trim white space in the end, vice versa. So how about to change reExtraSpace to /^\s*(.*?)\s*$/? so that it can do the real trim work? I don't know if it's right. It's just my advice.
 
Old December 19th, 2006, 01:46 PM
nzakas's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
Default

This has already been reported as an issue. Please refer to the errata page for more information: http://www.wrox.com/WileyCDA/WroxTit...ew_errata.html

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT TRIM Function sagrock XSLT 1 November 23rd, 2007 08:39 AM
TRIM, ISTEXT function won't work in Excel VBA code munzer1 Excel VBA 1 May 29th, 2007 09:35 AM
Trim MathLearner VB Databases Basics 2 May 16th, 2007 11:38 PM
custom JavaScript Trim function crmpicco Javascript How-To 2 January 18th, 2006 12:53 PM
Trim() NeoGeo ASP.NET 1.0 and 1.1 Basics 2 January 21st, 2004 11:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.