On Thursday, 24 October 2019 at 16:49:09 UTC, Mil58 wrote:
On Thursday, 24 October 2019 at 16:21:47 UTC, welkam wrote:
On Thursday, 24 October 2019 at 15:27:05 UTC, Mil58 wrote:
[...]

void main() {
    File("data.txt", "r+")
        .byLineCopy()
        .array()
        .each!writeln;
}

byLineCopy removes the new lines. If in the future you would need the new line symbol call byLineCopy(Yes.keepTerminator)

Sorry but not working ... Surely i'm not able to insert and adapt to my own script ! :-( Could you, please, modify with the right syntax at the right place ? - Thanks.
Ah sorry my bad. byLineCopy defaults to '\n' as line terminator so it worked on my system.

import std.algorithm;
File("data.txt", "r+")
    .byLineCopy(No.keepTerminator, '\r')
    .joiner(" - ")
    .writeln;

this will print the thing you wanted. If you want to capture that value in a variable then

auto result = File("data.txt", "r+")
                   .byLineCopy(No.keepTerminator, '\r')
                   .joiner(" - ");

Reply via email to