views:

170

answers:

1

Hi, When I try to output some data into a text file using FasterCSV, sometimes it adds the quotes to the concatenated string and sometimes it does not.

For instance:

FasterCSV.generate do |csv|      
  csv << ["E"+company_code]        
  csv << ["A"+company_name]
end

Both company_code and company_name are Strings and contains data but the output will show:

EtheCompanyCode
"AtheCompanyName"

I found how to force quoting in FasterCSV's docs but I need exactly the opposite and can not figure out why it quotes one line and not the other when they are both strings...

If anybody has the solution, I'll be deeply grateful for a lead :)

Thanks

A: 

If the real input is 'theCompanyName' and 'theCompanyCode' then I would also be confused by one line being quoted and the other not. But I suspect your real input is something else.

Most likely, the quoted line has some character that needs quoting, such as a comma; while the unquoted line doesn't. (Other characters that typically need quoting in Excel-style CSVs are quotation marks and newlines.)

John Y
Thanks for the hint!in my database: company_code = '01000 BOIS F' company_name = 'XL Projects, INC.'I just changed the company_name to "XL Projects INC" and the quote were removed...Nice, it would be cool if we could turn off quotes completely though... but I guess it defeat the purpose of a CSV export gem ;)Thanks!
Xavier Lozinguez