FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft (2008-06-30)

Discussion in 'Javascript' started by FAQ server, Jun 30, 2008.

  1. FAQ server

    FAQ server Guest

    -----------------------------------------------------------------------
    FAQ Topic - How do I trim whitespace -
    trim/trimRight/trimLeft
    -----------------------------------------------------------------------

    Using Regular Expressions (JavaScript 1.2/JScript 3+) :

    String.prototype.trimLeft =
    function()
    {
    return this.replace(/^\s+/,'');
    }
    String.prototype.trimRight =
    function()
    {
    return this.replace(/\s+$/,'');
    }
    String.prototype.trim =
    function()
    {
    return this.replace(/^\s+|\s+$/g,'');
    }

    http://docs.sun.com/source/816-6408-10/regexp.htm

    http://msdn2.microsoft.com/en-us/library/6wzad2b2.aspx

    http://en.wikipedia.org/wiki/Regular_expression

    http://www.informatics.sussex.ac.uk/courses/it/tutorials/nsJavaScriptRef/contents.htm

    http://www.merlyn.demon.co.uk/js-valid.htm


    --
    Postings such as this are automatically sent once a day. Their
    goal is to answer repeated questions, and to offer the content to
    the community for continuous evaluation/improvement. The complete
    comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
    The FAQ workers are a group of volunteers. The sendings of these
    daily posts are proficiently hosted by http://www.pair.com.
    FAQ server, Jun 30, 2008
    #1
    1. Advertising

  2. Re: FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft(2008-06-30)

    On Jun 29, 4:00 pm, "FAQ server" <> wrote:
    > -----------------------------------------------------------------------
    > FAQ Topic - How do I trim whitespace -
    > trim/trimRight/trimLeft
    > -----------------------------------------------------------------------
    >
    > Using Regular Expressions (JavaScript 1.2/JScript 3+) :
    >
    > String.prototype.trimLeft =
    > function()
    > {
    > return this.replace(/^\s+/,'');
    > }
    > String.prototype.trimRight =
    > function()
    > {
    > return this.replace(/\s+$/,'');
    > }
    > String.prototype.trim =
    > function()
    > {
    > return this.replace(/^\s+|\s+$/g,'');
    > }


    I thought these were scheduled for change ages ago so they did not
    augment built-in prototypes. Was that just forgotten or is the FAQ
    maintenance simply on hold for the time being?

    Peter
    Peter Michaux, Jun 30, 2008
    #2
    1. Advertising

  3. Re: FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft (2008-06-30)

    In comp.lang.javascript message <5a75db27-40fd-4371-ab6f-db88a9c6e957@q2
    7g2000prf.googlegroups.com>, Sun, 29 Jun 2008 16:23:04, Peter Michaux
    <> posted:
    >
    >I thought these were scheduled for change ages ago so they did not
    >augment built-in prototypes. Was that just forgotten or is the FAQ
    >maintenance simply on hold for the time being?
    >


    The FAQ maintainer has abandoned his duties, without giving notice.
    According to Google, that ID has posted nothing since February.

    --
    (c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
    Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
    Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
    No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
    Dr J R Stockton, Jun 30, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. FAQ server
    Replies:
    0
    Views:
    131
    FAQ server
    Aug 29, 2006
  2. FAQ server
    Replies:
    2
    Views:
    169
    Peter Michaux
    Dec 26, 2007
  3. FAQ server
    Replies:
    1
    Views:
    109
    Dr J R Stockton
    Feb 29, 2008
  4. FAQ server
    Replies:
    0
    Views:
    102
    FAQ server
    May 1, 2008
  5. FAQ server
    Replies:
    1
    Views:
    118
    Dr J R Stockton
    Aug 28, 2008
Loading...

Share This Page