Routine to remove extra newline chars and carriage return

Discussion in 'Javascript' started by vflyer, May 30, 2007.

  1. vflyer

    vflyer Guest

    vflyer, May 30, 2007
    #1
    1. Advertising

  2. vflyer

    Guest

    You can write one:

    String.prototype.rtrim = function() {
    return this.replace(/\n\r/,"");
    }
    , May 30, 2007
    #2
    1. Advertising

  3. On May 29, 8:11 pm, wrote:
    > You can write one:
    >
    > String.prototype.rtrim = function() {
    > return this.replace(/\n\r/,"");}


    String.prototype.rtrim = function() {
    return this.replace(/[\n\r]/,"");
    }
    scripts.contact, May 31, 2007
    #3
  4. scripts.contact wrote:

    > On May 29, 8:11 pm, wrote:
    >
    > > You can write one:

    >
    > > String.prototype.rtrim = function() {
    > > return this.replace(/\n\r/,"");}

    >
    > String.prototype.rtrim = function() {
    > return this.replace(/[\n\r]/,"");}


    No. The three most common EOLs are:

    \n (Linefeed)
    \r (Carriage return)
    \r\n (Carriage return followed by linefeed)

    But you also have:

    NEL = Next Line (\u0085)
    FF = Form Feed (\u000C)
    LS = Line Separator (\u2028)
    PS = Paragraph Separator (\u2029)

    A fully backwards compatible, Unicode-compliant regexp would be:

    /(\r\n|\r|\n|\u0085|\u000C|\u2028|\u2029)/g

    --
    Bart
    Bart Van der Donck, May 31, 2007
    #4
  5. On May 31, 2:29 pm, Bart Van der Donck <> wrote:
    > > String.prototype.rtrim = function() {
    > > return this.replace(/[\n\r]/,"");}

    >


    forgot the $ :
    return this.replace(/[\n\r]$/,"");}


    > A fully backwards compatible, Unicode-compliant regexp would be:
    >
    > /(\r\n|\r|\n|\u0085|\u000C|\u2028|\u2029)/g


    /(\r\n|\r|\n|\u0085|\u000C|\u2028|\u2029)$/
    scripts.contact, May 31, 2007
    #5
  6. On May 31, 2:29 pm, Bart Van der Donck <> wrote:
    > > String.prototype.rtrim = function() {
    > > return this.replace(/[\n\r]/,"");}

    >


    forgot the $ :
    return this.replace(/[\n\r]$/,"");}


    > A fully backwards compatible, Unicode-compliant regexp would be:
    >
    > /(\r\n|\r|\n|\u0085|\u000C|\u2028|\u2029)/g


    /(\r\n|\r|\n|\u0085|\u000C|\u2028|\u2029)$/
    scripts.contact, Jun 1, 2007
    #6
    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. =?Utf-8?B?V2ViTWF0cml4?=

    Newline & carriage return characters over SOAP HTTP

    =?Utf-8?B?V2ViTWF0cml4?=, Mar 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    677
    =?Utf-8?B?V2ViTWF0cml4?=
    Mar 13, 2006
  2. Replies:
    7
    Views:
    345
  3. mathieu
    Replies:
    3
    Views:
    585
    Bo Persson
    Sep 4, 2009
  4. WebMatrix

    Newline & carriage return charecters over SOAP HTTP

    WebMatrix, Mar 10, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    146
    WebMatrix
    Mar 10, 2006
  5. Steve Anderson
    Replies:
    3
    Views:
    239
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page