splitting numbers from a test file

Ali Çehreli acehreli at yahoo.com
Tue Sep 18 20:02:25 PDT 2012


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.

 > However, shouldn't splitter be returning an array (thats what the
 > docs seem to show)?

No, parts is a lazy range, which is ready to serve its elements as 
needed. If you want to convert its elements to an array eagerly, you can 
call std.array.array:

import std.array;
// ...

     writeln("There are ", array(parts).length,
             " numbers in line ", line_count++);

 > What is the type of 'parts'?

     writeln(typeid(parts));

or

     writeln(typeof(parts).stringof);

Ali

-- 
D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html



More information about the Digitalmars-d-learn mailing list