encoding/csv: improve Reader docs (#6828)
parent
00464ad988
commit
01a5b263e5
|
@ -28,6 +28,7 @@ pub mut:
|
|||
row_pos int
|
||||
}
|
||||
|
||||
// new_reader initializes a Reader with string data to parse
|
||||
pub fn new_reader(data string) &Reader {
|
||||
return &Reader{
|
||||
delimiter: `,`,
|
||||
|
@ -36,7 +37,8 @@ pub fn new_reader(data string) &Reader {
|
|||
}
|
||||
}
|
||||
|
||||
// read() reads one row from the csv file
|
||||
// read reads a row from the CSV data.
|
||||
// If successful, the result holds an array of each column's data.
|
||||
pub fn (mut r Reader) read() ?[]string {
|
||||
l := r.read_record()?
|
||||
return l
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
## Reader example
|
||||
|
||||
```v
|
||||
import encoding.csv
|
||||
|
||||
data := 'x,y\na,b,c\n'
|
||||
mut parser := csv.new_reader(data)
|
||||
|
||||
// read each line
|
||||
for {
|
||||
items := parser.read() or {break}
|
||||
println(items)
|
||||
}
|
||||
```
|
||||
It prints:
|
||||
```
|
||||
['x', 'y']
|
||||
['a', 'b', 'c']
|
||||
```
|
Loading…
Reference in New Issue