std.file.readText() extra Line Feed character

Colin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 18 01:18:35 PST 2014


Why does std.file.readText() append a Line Feed char onto the end 
of the string?

I have a file with the following contents in it:
Name   =               Int
Other=Float
One More = String(Random;)

I then have the code:

void main(string[] args){
     const text = "Name   =               Int
Other=Float
One More = String(Random;)";

     string input = readText(args[1]);

     writefln("Raw data");
     writefln("D)    %s", cast(ubyte[])text[$-5..$]);
     writefln("File) %s", cast(ubyte[])input[$-5..$]);

}

This produces:
Raw data
D)    [100, 111, 109, 59, 41]
File) [111, 109, 59, 41, 10]

Any Idea why the reading from the File adds on that extra '10' 
character?

I don't think it's my editor adding chars to the end of the file, 
as I'm using vi.


More information about the Digitalmars-d-learn mailing list