47381RE: Removing blank lines from a string
- Feb 2, 2004
> -----Original Message-----That is brilliant, thanks.
> 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.
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.
And this part to get blanks lines in the middle of the string:
But I don't understand this part to get rid of the empty lines up to the end
of the string:
Ahh, I think I understand. That matches the last \n with zero width, so it
include it in the pattern. Therefore, a blank substitution can be used.
- << Previous post in topic