wrapCsvQuotes method

  1. @useResult
String wrapCsvQuotes()

Wraps this string in double quotes and doubles any internal double quotes.

Returns a new string with CSV-style quoting applied.

Example:

'a"b'.wrapCsvQuotes();  // '"a""b"'
'normal'.wrapCsvQuotes();  // '"normal"'

Implementation

@useResult
String wrapCsvQuotes() {
  final String escaped = replaceAll('"', '""');
  return '"$escaped"';
}