Why does readln include the line terminator?

Daniel Keep daniel.keep.lists at gmail.com
Tue Apr 14 00:55:27 PDT 2009


Georg Wrede wrote:
> Readln returns a string which contains the line terminator.
> 
> Is there a grand reason for this?
> 
> 
> Currently there are a few drawbacks with this. The naive user doesn't
> expect it, and the seasoned user has to keep stripping it. And then he
> has to search the docs (or get hold of other OSs) to determine what
> terminator to expect on other systems.
> 
> And it can't really be a speed optimization either, because to do
> anything useful with a string, you have to strip the terminator anyway
> at some point.

Because if it stripped it, there's no way to know what it was.  If you
want to do per-line processing but don't want to clobber the line
endings, readln has to return the line terminator.

Besides which, it's a single function call to strip it off irrespective
of OS.

  -- Daniel



More information about the Digitalmars-d mailing list