PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs223] remove trailing newlines
Date: Monday, 23 Mar 2020, 10:22:34


    > Message Posted By: Unknown
    >
    > 1. Does trailing newlines refer to the newline character after each line?
    > Or does it refer to newlines at the end of a file? (for example, if a file
    > has 10 lines in total: 2 non-empty lines, and 8 empty lines, do we ignore
    > the last 8 newline characters? or do we treat them as proper lines?)

Yes, the trailing newline is the newline that appears
at the end of every line except possibly for the last.

You treat the "empty" lines as containing empty strings.
=====

    > 2. If a file ends with a newline, should the last empty line be treated as
    > a line?

Yes.
=====

    > 3. What is the point of removing trailing newlines? Can't we just process
    > each line with the last character as a newline?

Hint: '\t' < '\n', but for sorting purposes you want
"a" < "a\tb".

--Stan-
PREV INDEX NEXT