Comma-separated values (CSV) are a popular text format to interchange data. Gforth provides words for reading CSV files (with all features, including newlines in quoted strings).
Read CVS file addr u and execute xt for every field
found. Xt has the stack effect ( addr u field line
-- )
, i.e. the field string (in de-quoted form), the current
field number (starting with 0), and the current line (starting
with 1).
CSV field separator (default is ‘,’, hence the name
"comma-separated"); this is a value and can be
changed with to csv-separator
.
CSV quote character (default is ‘"’); this is a value and can be
changed with to csv-quote
.
print a field in CSV format, i.e., with enough quotes that
read-csv
will produce c-addr u when encountering the
output of .quoted-csv
.