Remove all blank lines from a file

Stefan Koch via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 31 07:54:04 PDT 2017


On Thursday, 31 August 2017 at 14:44:07 UTC, vino wrote:
> Hi All,
>
>   Can some provide me a example of how to remove all blank 
> lines from a file.
>
> From,
> Vino.B

ubyte[] fileData;
ubyte[] writeThis;
uint lastP;

fileData = readRaw(fileName);

foreach(uint p; ubyte b;fileData)
{
     if (b == '\n')
     {
         writeThis ~= fileData[lastP .. p];
         lastP = p;
     }
}

write(fileName, fileData);


More information about the Digitalmars-d-learn mailing list