Reading a line from stdin

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Wed Mar 16 03:31:46 PDT 2011


On Wed, 16 Mar 2011 11:20:43 +0100, spir wrote:

> On 03/16/2011 06:41 AM, Jesse Phillips wrote:
>> Ali Çehreli Wrote:
>>
>>> Right? Is there a better way that I am missing?
>>>
>>> Thank you,
>>> Ali
>>
>> No better way, the stated reason IIRC is that it is easier to remove
>> the new line then to append it back on.
> 
> May be stated, but it is very wrong! I guess:
> 
>      s = s ~ '\n';
> versus
>      if ((str[$-1] == '\n') || (str[$-1] == '\r')) {
>          str = str[0..$-1];
>          if ((str[$-1] == '\n') || (str[$-1] == '\r')) {
>              str = str[0..$-1];
>          }
>      }

That comparison seems a bit biased. :)  This one is more fair:

    import std.path;
    ...
    s ~= linesep;

versus

    import std.string;
    ...
    s = s.chomp;

-Lars


More information about the Digitalmars-d-learn mailing list