Read Complete File to Array of Lines

Paul phshaffer at gmail.com
Fri May 11 14:13:40 PDT 2012


On Friday, 11 May 2012 at 20:43:47 UTC, Era Scarecrow wrote:
> On Friday, 11 May 2012 at 20:40:23 UTC, Paul wrote:
>> On Friday, 11 May 2012 at 18:02:54 UTC, Jesse Phillips wrote:
>>> void main() {
>>>    foreach(line; readText("file.in").splitLines()) ...
>>> }
>>
>> Thanks Jesse.
>> I'm finding that I can't just substitute args[1] for a text 
>> string.  Is there a clever way to use args[] in place of your 
>> "file.in"?
>
> Why not?
>
> void main(string[] args) {
>     if(args.length > 1) {
>         foreach(line; readText(args[1]).splitLines()) ...
>     }
> }

This is my program:

import std.stdio,std.string,std.file;

// Main function
void main(string[] args){
     if (args.length > 1){
         foreach(line; readText(args[1]).splitLines()) {
             writefln("line : %s", line);
             //if (n > 10) break;
         }
     }
}

I get this:

std.utf.UTFException at std\utf.d(644): Invalid UTF-8 sequence (at 
index 1)
----------------
41E424
41E29B
4020F3
4020C1
402042
4077A4
4077E3
4073F3
438781
----------------

These are the first few lines of my text file:
NAME   = XPAW01_STA
   TYPE   = COMPND
   DESCRP =
   PERIOD = 1
   PHASE  = 0
   ON     = 0
   INITON = 2
   CINHIB = 0
   GR1DV1 =
   GR1DV2 =
   GR1DV3 =
   GR1DV4 =



More information about the Digitalmars-d-learn mailing list