Why does readln include the line terminator?

Georg Wrede georg.wrede at iki.fi
Tue Apr 14 12:24:56 PDT 2009


bearophile wrote:
> Georg Wrede:
>> This seems a bit laborious. Replacing stuff at the end of the string 
>> forces him to check, for *each* line, the length of the terminator, and 
>> then use ...$-1 and at other times ...$-2, etc. in his code.
> 
> You use a string function or string method that removes the eventually present ending newline, any kind of. There is one in std.string too. Its main problem (beside working with char[] only in D1) is that its name is too much similar to another string function. I have complained about this time ago.
> 
> Regarding the newline at the end of lines, in Python:
> for line in file("somefilename.txt"):
>     print line
> line contains the ending new line too.

Your code ends up printing the output on every other line.



More information about the Digitalmars-d mailing list