Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: RE: JavaScript 'trim' equivalent


Message #1 by "Alex Shiell, ITS, EB, SE" <alex.shiell@s...> on Wed, 1 May 2002 12:20:16 +0100
That only works for one space at each end...

OK the final expression, which works properly is:

/^\s*|\s*$/g;

-----Original Message-----
From: Chris Scott [mailto:chris@e...]
Sent: 01 May 2002 13:10
To: javascript
Subject: [javascript] RE: JavaScript 'trim' equivalent


> which strips the leading spaces regardless of wether or not there are
> trailing spaces.  Still doesn't trim the trailing spaces though...

This does...

function trim(string)
{
var re= /^\s|\s$/g;
return string.replace(re,"");
}




---

Improve your web design skills with these new books from Glasshaus.

Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20

________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com

Headquarters Address & Contact Numbers

150 Broomielaw
5 Atlantic Quay
Glasgow
G2 8LU.
Tel:  +44 (0) 141 248 2700.
Fax:  +44 (0)141 221 3217

 This message is sent in confidence for the addressee only.
It may contain legally privileged information. The contents are not to
be disclosed to anyone other than the addressee. Unauthorised recipients
are requested to preserve this confidentiality and to advise the sender
immediately of any error in transmission.



  Return to Index