Why does readln include the line terminator?

bearophile bearophileHUGS at lycos.com
Tue Apr 14 09:25:20 PDT 2009


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.

Bye,
bearophile



More information about the Digitalmars-d mailing list