Public.Standards.CSV
This module was made following http://en.wikipedia.org/wiki/Comma-separated_valuesThe examples shown below use the sample CSV file provided by the fore-mentionned documentation.1 FilesPublic.Standards.CSV.FILE() inherits from the buffered Stdio.FILE() class.It sports two important methods:
object infile = Public.Standards.CSV.FILE("/tmp/sample.csv", "r");
infile->read_row();
(1) Result: ({ /* 5 elements */
"1997",
"Ford",
"E350",
"ac, abs, moon",
"3000.00"
})
object infile = Public.Standards.CSV.FILE("/tmp/sample.csv", "r");
foreach(infile; int line_number; array data) {
//...
}
Writing
object outfile = Public.Standards.CSV.FILE("/tmp/foo.csv", "cw");
outfile->write_row("foo","bar","baz");
(1) Result: 13
StringPublic.Standards.CSV.CSVString() deals with string.As a side note, the name Public.Standards.CSV.String() was originally chosen for consistency, but produced unexpected results i didn't managed to overcome. Anyone with a clue here is welcomed.Public.Standards.CSV.CSVString() work the very same way than Public.Standards.CSV.FILE()1.1 ReadingThe method way:
object data = Public.Standards.CSV.CSVString(Stdio.read_bytes("/tmp/sample.csv"));
data->read_row();
(3) Result: ({ /* 5 elements */
"1997",
"Ford",
"E350",
"ac, abs, moon",
"3000.00"
})
object instring = Public.Standards.CSV.CSVString(Stdio.read_bytes("/tmp/sample.csv"));
foreach(instring; int line_number; array dara) {
// ...
}
WritingPublic.Standards.CSV.CSVString() doesn't support writing for now.Powered by PikeWiki2 |
|||
| gotpike.org | Copyright © 2004 - 2009 | Pike is a trademark of Department of Computer and Information Science, Linköping University | |||