Standard Library
class CsvRows
The sequence of rows read from a CSV file.
since 0.1.0-alpha.1linuxwindowswasm
- bases
IIterable<Array<string>>
Overview
Most code does not construct this class directly: csv::rows creates one and wraps it as a Seq. It reads from the file it is given, one record at a time, and every iterator made from it continues from where the previous one stopped, so the rows can be read only once. It does not close the file.
Examples
Iterating the rows of a file
File input = File("/dev/stdin", std::read);
CsvRows source = CsvRows(input, 44);
IIterator<Array<string>> it = source.iterator();
while (it.hasNext()) {
Array<string> row = it.next();
console.writeln(row.length().toString() + ": " + row.joinToString("|"));
}
input.close();
id,name
7,"Doe, Jane"
2: id|name
2: 7|Doe, Jane
Constructors
new
new(File file, int delimCode)Create a row source over a file.
Parameters
- file
- The open file to read from; it is not closed by the reader.
- delimCode
- The code of the field delimiter character, for example
44for a comma or9for a tab. Unlikecsv::rows, this constructor does not validate it.
Examples
File input = File("/dev/stdin", std::read);
IIterator<Array<string>> it = CsvRows(input, 59).iterator();
console.writeln(it.next().joinToString("|"));
input.close();
a;b;c
a|b|c
Fields
dcode
int dcodeThe delimiter as a character code; 44 is a comma.
f
File fThe file the rows are read from.
Methods
iterator
Start reading rows.
Each call returns a new iterator over the same file position, so a second iterator continues where the first one stopped rather than starting again.
Returns
An iterator whose next gives each row as an array of fields.
Examples
File input = File("/dev/stdin", std::read);
CsvRows source = CsvRows(input, 44);
IIterator<Array<string>> first = source.iterator();
console.writeln(first.next().joinToString("|"));
IIterator<Array<string>> second = source.iterator();
console.writeln(second.next().joinToString("|"));
input.close();
a,b
c,d
e,f
a|b
c|d