Loading ...
Sorry, an error occurred while loading the content.

Re: Removing blank lines from a string

Expand Messages
  • Suresh Govindachar
    Klaus Bosau On: Saturday, January 31, 2004 8:54 PM ... [My previous solution for handling multiple blank lines at the beginning only handled up to two blank
    Message 1 of 10 , Jan 31, 2004
    • 0 Attachment
      "Klaus Bosau" On: Saturday, January 31, 2004 8:54 PM
      >
      >Would this solve your problem?
      >
      > substitute(@a, '^\n\|\n\s*\n\@=', '', 'g')

      [My previous solution for handling multiple blank lines at the
      beginning only handled up to two blank lines at the beginning]

      I think the following is the solution:

      substitute(@a, '^\(\s*\n\)*\|\n\s*\n\@=', '', 'g')

      I have tested it with 0 or more blank lines at the beginning,
      at the end and in between two non-trivial lines; blank lines
      with and without white space; non-trivial lines starting and
      ending with and without blank space.

      --Suresh
    • David Fishburn
      ... That is brilliant, thanks. I have run my own tests, and it does exactly what I need. I understand this part to get rid of empty lines at the start of the
      Message 2 of 10 , Feb 2, 2004
      • 0 Attachment
        > -----Original Message-----
        > From: Suresh Govindachar [mailto:sgovindachar@...]
        > I think the following is the solution:
        >
        > substitute(@a, '^\(\s*\n\)*\|\n\s*\n\@=', '', 'g')
        >
        > I have tested it with 0 or more blank lines at the beginning,
        > at the end and in between two non-trivial lines; blank lines
        > with and without white space; non-trivial lines starting and
        > ending with and without blank space.


        That is brilliant, thanks.

        I have run my own tests, and it does exactly what I need.

        I understand this part to get rid of empty lines at the start of the string.
        '^\(\s*\n\)*

        And this part to get blanks lines in the middle of the string:
        \n\s*\n

        But I don't understand this part to get rid of the empty lines up to the end
        of the string:
        \n\s*\n\@=

        Ahh, I think I understand. That matches the last \n with zero width, so it
        does not
        include it in the pattern. Therefore, a blank substitution can be used.

        Thanks!
        Dave
      Your message has been successfully submitted and would be delivered to recipients shortly.