CSV Parser
The CSVParser script is a script for reading CSV files and parsing them into Director lists. It can also be used to write lists of lists back out to CSV files. Here is a small demo movie that will read CSV files and display them as tables in Director. The script uses the PregEx Xtra to read and write files, as well as processing text with RegExp.
Note that this script treats any CR, LF or CRLF as record separators. This means that this script doesn't allow for embedded line breaks (which the CSV format allows for). Fields are quoted if they contains double-quotes, commas or leading/trailing white space. White space is preserved if quoted - but note that Excel will try to be 'helpful' (in a very Microsoft way) and trim whitespace even if it is quoted.
If your fields may include linebreaks, then MediaMacros has another CSV parsing script that will handle embedded line breaks.
Richard said
Hi,
I found your CSV Parser Lingo scripts, and generally am very happy with it.There is one bug though:
If the last field of a record (line) is empty and not quoted, then this field will not show up as an item in the Lingo list.
This leaves you with records that have 1 field/item less than others, and that is very annoying.
I added a line in the script, that adds 2 double quotes at the end of the lone, if that line ends in a comma.
This solves the problem, but is not very elegant.
I think you might review the regex that does the splitting of the line.
Anyway, thank you very much for the script, it has saved me a tremendous amount of time so far!
Regards,
Richard.
Posted 7th April, 2007