There's more...

If you need to read or write a custom CSV format, like one that uses tabs instead of commas as a delimiter, you can use WriterBuilder and ReaderBuilder to customize the expected format. Remember this well if you're planning on using Microsoft Excel, as it has the annoying tendency to be regionally inconsistent in its choice of delimiters (https://stackoverflow.com/questions/10140999/csv-with-comma-or-semicolon).

When working with CSV and Microsoft Excel, be careful and sanitize your data before handing it to Excel. Even though CSV is defined as plain data with no control identifiers, Excel will interpret and execute macros when importing CSV. For examples of possible attack vectors opened by this, see http://georgemauer.net/2017/10/07/csv-injection.html.

This is also useful if a Windows application refuses to accept the terminator that csv uses as per default. In this case, simply specify the following code in the builder to use the Windows-native   terminator:

.terminator(csv::Terminator::CRLF)

The csv crate allows you to manipulate your data much more than what is shown in this recipe. You can, for example, insert new fields on the fly into a StringRecord. We deliberately don't explore these possibilities in detail as the CSV format is not meant for these kinds of data manipulation. If you need to do more than simple import/export, you should use a more suitable format, such as JSON, which we will explore in this chapter as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.189.23