readln() returns new line charater
Dmitry Olshansky
dmitry.olsh at gmail.com
Sun Dec 29 10:44:58 PST 2013
28-Dec-2013 21:13, Vladimir Panteleev пишет:
> On Saturday, 28 December 2013 at 17:07:58 UTC, Andrei Alexandrescu wrote:
>> On 12/28/13 8:50 AM, Jeroen Bollen wrote:
>>> On Saturday, 28 December 2013 at 16:49:15 UTC, Jeroen Bollen wrote:
>>>> Why is when you do readln() the newline character (\n) gets read too?
>>>> Wouldn't it make more sense for that character to be stripped off?
>>>
>>> I just want to add to this, that it makes it really annoying to work
>>> with the command line, as you kinda have to strip off the last character
>>> and thus cannot make the string immutable.
>>
>> Try stdin.byLine, which by default strips the newline.
>
> stdin.byLine can't strip \r\n unless you specify that as the line
> terminator, in which case it can't split by \n.
I've come to conclusion that the only sane line ending behavior is to do
what Unicode standard says, and detect the following pattern as line
separator:
\r\n | \r | \f | \v | \n | \u0085 | \u2028 | \u2029
This includes never breaking a line in between \r\n sequence.
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list