std.file.readText() extra Line Feed character

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 18 01:25:37 PST 2014


On Thu, 18 Dec 2014 09:18:35 +0000
Colin via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> 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.

you *definetely* has the last line ended with '\n'.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141218/76d73245/attachment.sig>


More information about the Digitalmars-d-learn mailing list