Re: Read Complete File to Array of Lines

2014-05-06 Thread Suliman via Digitalmars-d-learn
I am trying to write simple parser, that split text to key value name = david lastname = wood here is my code: foreach (line; readText(confname).splitLines()) { writeln(line); foreach (str; split(line, "="))

Re: Read Complete File to Array of Lines

2012-05-11 Thread Era Scarecrow
On Friday, 11 May 2012 at 21:13:41 UTC, Paul wrote: std.utf.UTFException@std\utf.d(644): Invalid UTF-8 sequence (at index 1) What are you reading? If it's regular text (0-127) then you shouldn't have an issue. However 128-255 (or, -1 to -127) are treated differently. D by default is UTF-8 or

Re: Read Complete File to Array of Lines

2012-05-11 Thread Paul
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 sub

Re: Read Complete File to Array of Lines

2012-05-11 Thread Era Scarecrow
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

Re: Read Complete File to Array of Lines

2012-05-11 Thread Paul
On Friday, 11 May 2012 at 18:02:54 UTC, Jesse Phillips wrote: On Friday, 11 May 2012 at 15:00:18 UTC, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? Thanks

Re: Read Complete File to Array of Lines

2012-05-11 Thread Paul
On Friday, 11 May 2012 at 19:24:49 UTC, Graham Fawcett wrote: On Friday, 11 May 2012 at 18:57:52 UTC, Steven Schveighoffer wrote: On Fri, 11 May 2012 11:00:16 -0400, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) e

Re: Read Complete File to Array of Lines

2012-05-11 Thread Graham Fawcett
On Friday, 11 May 2012 at 20:06:45 UTC, Era Scarecrow wrote: On Friday, 11 May 2012 at 19:24:49 UTC, Graham Fawcett wrote: It sure would. I suspect that Jesse's approach... readText("file.in").splitLines() ...would be the most efficient way if you need an actual array: slurp the whole file a

Re: Read Complete File to Array of Lines

2012-05-11 Thread Era Scarecrow
On Friday, 11 May 2012 at 20:06:45 UTC, Era Scarecrow wrote: On Friday, 11 May 2012 at 19:24:49 UTC, Graham Fawcett wrote: It sure would. I suspect that Jesse's approach... readText("file.in").splitLines() ...would be the most efficient way if you need an actual array: slurp the whole file

Re: Read Complete File to Array of Lines

2012-05-11 Thread Era Scarecrow
On Friday, 11 May 2012 at 19:24:49 UTC, Graham Fawcett wrote: It sure would. I suspect that Jesse's approach... readText("file.in").splitLines() ...would be the most efficient way if you need an actual array: slurp the whole file at once, then create an array of memory-sharing slices. Do

Re: Read Complete File to Array of Lines

2012-05-11 Thread Graham Fawcett
On Friday, 11 May 2012 at 18:57:52 UTC, Steven Schveighoffer wrote: On Fri, 11 May 2012 11:00:16 -0400, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? Tha

Re: Read Complete File to Array of Lines

2012-05-11 Thread Steven Schveighoffer
On Fri, 11 May 2012 11:00:16 -0400, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? Thanks Would something like this work? auto arr = array(map!"a.idup"(

Re: Read Complete File to Array of Lines

2012-05-11 Thread Graham Fawcett
On Friday, 11 May 2012 at 15:00:18 UTC, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? Thanks If you use the "byLine" approach... foreach(line; File("myf

Re: Read Complete File to Array of Lines

2012-05-11 Thread Jesse Phillips
On Friday, 11 May 2012 at 15:00:18 UTC, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? Thanks Something like: import std.file; import std.string; void mai

Re: Read Complete File to Array of Lines

2012-05-11 Thread Graham Fawcett
On Friday, 11 May 2012 at 15:18:11 UTC, H. S. Teoh wrote: On Fri, May 11, 2012 at 05:00:16PM +0200, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? import st

Re: Read Complete File to Array of Lines

2012-05-11 Thread H. S. Teoh
On Fri, May 11, 2012 at 05:00:16PM +0200, Paul wrote: > I would like to read a complete file in one statement and then > process it line by line. > > foreach (line; MyFile) > etc. > > Is it possible to read a file into and array of lines? import std.array; import std.stdio; string[] getLines(Fi

Re: Read Complete File to Array of Lines

2012-05-11 Thread sclytrack
On 05/11/2012 05:00 PM, Paul wrote: I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? Thanks ---SOURCE import std.stdio; import std.file; int main() { writeln("s

Read Complete File to Array of Lines

2012-05-11 Thread Paul
I would like to read a complete file in one statement and then process it line by line. foreach (line; MyFile) etc. Is it possible to read a file into and array of lines? Thanks