To give Julian a hand with those early morning blues (it's late afternoon
here in France - I've had time to recover!):
str_String.replace(/^\s*(.*\S|.*)\s*$/, '$1');
Anil
Sevina Technologies
www.Sevina.com
----- Original Message -----
From: "Julian Dobson" <juliand@w...>
To: "javascript" <javascript@p...>
Sent: Wednesday, February 28, 2001 3:25 PM
Subject: [javascript] Re: how to trim the leading and trailing spaces in a
string
> The easiest way is to use a Regular Expression to remove the offending
> white space:
>
> function fnc_trim(str_String)
> {
> return str_String.replace(/^\s*/, '').replace(/\s*$/,'');
> }
>
> It should be possible to use a single replace to do the same thing, as in:
>
> str_String.replace(/^\s*(.*)\s*$/, '$1');
>
> But this doesn't remove the trailing whitespace, and I'm too dense this
> morning to figure out why - the caffine hasn't kicked in yet.
>
> Julian
>
> > Hi:
> >
> > Are there any function or method in JavaScript which is equivalent to
> > VBScript's trim() function? I need to trim the leading and trailing
> > spaces of a string.
> >
>
>