6.24.9 CSV Reader

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-csv ( c-addr u xt –  ) gforth-experimental

Read the CSV file with the name given by c-addr u and execute xt for every field found.
Xt ( c-addr2 u2 field line -- ) is called once for each field; c-addr2 u2 is the decoded field content, field is the field number (starting with 0), and line is the line number (starting with 1).

csv-separator ( – c  ) gforth-experimental

CSV field separator (default is ‘,’, hence the name "comma-separated"); this is a value and can be changed with to csv-separator.

csv-quote ( – c  ) gforth-experimental

CSV quote character (default is "); this is a value and can be changed with to csv-quote.

.quoted-csv ( c-addr u –  ) gforth-experimental “dot-quoted-csv”

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.