swiftcsv / SwiftCSV

CSV parser for Swift
MIT License
947 stars 190 forks source link

Issue With Comma With Quotations #129

Closed felswa closed 1 year ago

felswa commented 1 year ago

I have a 3rd part file as below where it has a comma with "5,000" which I do not want to be parsed into 2 separates items but SwiftCSV seems to do this. Is there any way to fix this? Thanks.

"Date","Action","Symbol","Description","Quantity","Price","Fees & Comm","Amount"
"08/22/2023","Buy","912797GM3","US TREASURY BILL24U S T BILL DUE 02/08/24","5,000","$97.5285","","-$4876.42"

result is:

["Action": "Buy", "Symbol": "912797GM3", "Quantity": "5", "Amount": "", "Description": "US TREASURY BILL24U S T BILL DUE 02/08/24", "Date": "08/22/2023", "Fees & Comm": "$97.5285", "Price": "000"]  
Diggory commented 1 year ago

Works for me. Both when initialising from an URL or a string.

        let sampleCSVTest = """
"Date","Action","Symbol","Description","Quantity","Price","Fees & Comm","Amount"
"08/22/2023","Buy","912797GM3","US TREASURY BILL24U S T BILL DUE 02/08/24","5,000","$97.5285","","-$4876.42"
"""
        do {
            csv = try CSV<Named>(string: sampleCSVTest)
        } catch {
            XCTAssert(false, "Could not create CSV instance from: \(sampleCSVTest)")
        }

        for (index, row) in csv.rows.enumerated() {
            print(row)
        }
Executed 43 tests, with 0 failures (0 unexpected) in 0.412 (0.417) seconds
["Date": "08/22/2023", "Fees & Comm": "", "Symbol": "912797GM3", "Amount": "-$4876.42", "Quantity": "5,000", "Price": "$97.5285", "Description": "US TREASURY BILL24U S T BILL DUE 02/08/24", "Action": "Buy"]
Diggory commented 1 year ago

Could you perhaps link to a sample CSV file?

felswa commented 1 year ago

Apologies. It does work. Issue was when Excel re-saves a CSV file the quotations were dropped.