csvFormatRow

Formats an array (or a single scalar, treated as a one-column row) as a CSV row string. A field is quoted when quoteAll is true or the field contains the delimiter, the quote character, or a newline; the quote and escape characters are doubled inside quoted fields. A null element produces an empty, unquoted field. This matches the opencsv behaviour of the Java CSV shim, keeping round-trips byte-identical.

csvFormatRow(values [, delimiter] [, quote] [, escape] [, quoteAll]) → returns string

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

values array
Required

Array of values to format (or a single scalar for a one-column row).

delimiter string
Default: ,

Single-character field delimiter (default comma).

quote string
Default: "

Single-character quote character (default double-quote).

escape string
Default: "

Single-character escape character (default the quote character).

quoteAll boolean
Default: true

Quote every field, not only those that need it (default true).
Values:
  • true
  • false

Examples
Sample code invoking the csvFormatRow function

Quote-all formatting of a simple array.

writeDump(csvFormatRow(["Alice", 90, "said \"hi\""]));

Expected Result: "Alice","90","said \"hi\""

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub