Re: splitting numbers from a test file

2012-09-19 Thread Ali Çehreli
On 09/19/2012 10:22 AM, Craig Dillabaugh wrote: > Thank you for your help. Also Ali thanks for your book, motivated > by this little problem I've started reading your Chapter on > ranges. It is very helpful. Thank you. :) Obviously, I am aware of its shortcomings. Especially, the difference be

Re: splitting numbers from a test file

2012-09-19 Thread Craig Dillabaugh
On Wednesday, 19 September 2012 at 06:09:38 UTC, Ali Çehreli wrote: On 09/18/2012 09:56 PM, Craig Dillabaugh wrote: > On Wednesday, 19 September 2012 at 04:03:44 UTC, Jonathan M Davis > wrote: >> The documentation says that it returns a range. > From: > http://dlang.org/phobos/std_array.html#sp

Re: splitting numbers from a test file

2012-09-18 Thread Jonathan M Davis
On Wednesday, September 19, 2012 06:56:23 Craig Dillabaugh wrote: > From: > http://dlang.org/phobos/std_array.html#splitter Ah. I was looking at std.algorithm.splitter (which operates on generic ranges and separators) which _does_ explicitly say that it returns a range. Yeah. The documentation o

Re: splitting numbers from a test file

2012-09-18 Thread Ali Çehreli
On 09/18/2012 09:56 PM, Craig Dillabaugh wrote: > On Wednesday, 19 September 2012 at 04:03:44 UTC, Jonathan M Davis > wrote: >> The documentation says that it returns a range. > From: > http://dlang.org/phobos/std_array.html#splitter > > The documentation (copied and pasted) for splitter reads:

Re: splitting numbers from a test file

2012-09-18 Thread Craig Dillabaugh
On Wednesday, 19 September 2012 at 04:03:44 UTC, Jonathan M Davis wrote: On Wednesday, September 19, 2012 05:36:36 Craig Dillabaugh wrote: Thanks, a few others have pointed that out to me too. But as a D newbie how would I have any clue what splitter returns since the return type is auto? T

Re: splitting numbers from a test file

2012-09-18 Thread Jonathan M Davis
On Wednesday, September 19, 2012 05:36:36 Craig Dillabaugh wrote: > Thanks, a few others have pointed that out to me too. But as a D > newbie how would I have any clue what splitter returns since the > return type is auto? The documentation says that it returns a range. Presumably then, the probl

Re: splitting numbers from a test file

2012-09-18 Thread Craig Dillabaugh
On Wednesday, 19 September 2012 at 03:12:21 UTC, Jonathan M Davis wrote: On Wednesday, September 19, 2012 04:50:45 Craig Dillabaugh wrote: Hello I am trying to read in a set of numbers from a text file. The file in questions looks something like this: 35 2 0 1 00.4946354869998

Re: splitting numbers from a test file

2012-09-18 Thread Craig Dillabaugh
On Wednesday, 19 September 2012 at 02:58:33 UTC, bearophile wrote: Craig Dillabaugh: 8auto f = std.stdio.File("test.txt", "r"); 9foreach( char[] s; f.byLine() ) { 10 string line = std.string.strip( to!string(s) ); 11 auto parts = std.array.splitter( line ); 12 writeln("There

Re: splitting numbers from a test file

2012-09-18 Thread Jonathan M Davis
On Wednesday, September 19, 2012 04:50:45 Craig Dillabaugh wrote: > Hello I am trying to read in a set of numbers from a text file. > The file in questions looks something like this: > > 35 2 0 1 > 00.4946354869998 0.88077994719970 > 10.6067210994997 0.225420

Re: splitting numbers from a test file

2012-09-18 Thread Ali Çehreli
On 09/18/2012 07:50 PM, Craig Dillabaugh wrote: > 11 auto parts = std.array.splitter( line ); > 12 writeln("There are ", parts.length, " numbers in line ", > When I try to compile this I get an error: > test.d(12): Error undefined identifier 'length; That is a very common confusion with ranges.

Re: splitting numbers from a test file

2012-09-18 Thread bearophile
Craig Dillabaugh: 8auto f = std.stdio.File("test.txt", "r"); 9foreach( char[] s; f.byLine() ) { 10 string line = std.string.strip( to!string(s) ); 11 auto parts = std.array.splitter( line ); 12 writeln("There are ", parts.length, " numbers in line ", line_count++); 13 for

splitting numbers from a test file

2012-09-18 Thread Craig Dillabaugh
Hello I am trying to read in a set of numbers from a text file. The file in questions looks something like this: 35 2 0 1 00.4946354869998 0.88077994719970 10.6067210994997 0.22542087170 After each line I want to check how many numbers were on the line I