INPUTCSV does not accept embedded quotes

From Liberty BASIC Family
Jump to navigation Jump to search

Description

LB 4.5.0 contains a new statement INPUTCSV to read records from a Comma-Separated Value file. However it does not correctly accept records that contain embedded quotes (which in the standard CSV format are doubled up from " to ""). For example the record "Venture ""Extended Edition, Very Large""" should be read as Venture "Extended Edition, Very Large" but this does not work.

Example code to demonstrate the bug.

Save this example from the Wikipedia article to the file test.csv:

Year,Make,Model,Description,Price
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00

Now run this program:

    open "test.csv" for input as #f
    while not(eof(#f))
        inputcsv #f, year$, make$, model$, desc$, price$
        print year$; tab(7); make$; tab(14); model$;
        print tab(45); desc$; tab(65); price$
    wend
    close #f
    end

This is the expected output:

Year  Make   Model                          Description         Price
1997  Ford   E350                           ac, abs, moon       3000.00
1999  Chevy  Venture "Extended Edition"                         4900.00
1999  Chevy  Venture "Extended Edition, Very Large"             5000.00
1996  Jeep   Grand Cherokee                 MUST SELL!
air, moon roof, loaded                                          4799.00