Oh, sit back down James, let me take this reply.
I don't know what version of Excel you are using, but I've got Microsoft Office 2004 for Mac on my system and if I start with your text in /tmp/notcsv.csv, open it in Excel, put =LEN(A1) in cell A2 and '=LEN(A1) in cell A3 (and similarly for B2..C3), save it as ~/Documents/fromExcel.csv as a "CSV (Comma-delimited)" type, then I get this:
$ head /tmp/notcsv.csv ~/Documents/fromExcel.csv
==> /tmp/notcsv.csv <==
"abc", "sdfds "string"ddsfdsf", "xyz", "pqr"
==> /Users/rab/Documents/fromExcel.csv <==
abc," ""sdfds ""string""ddsfdsf"""," ""xyz"""," ""pqr"""
3,24,7,6
=LEN(A1),=LEN(B1),=LEN(C1),=LEN(D1)
So you seem to be missing some quotes in your output. Note that the first field had quotes in the original, but they are not required (no leading spaces, no comma or quote in the value). The original file, while technically invalid, is read by Excel and interpreted in a reasonable way. The output is strictly conforming to the CSV spec (although yours seems not to be).
As others have said, you'll have to parse it yourself if you need to accept a sloppy input format.
You also seem to have the impression that rails is somehow "more" than ruby. It isn't "more" than ruby, it just is written in ruby like any other ruby program you might write to handle the data. Just decide how each of the line types ought to be interpreted, write down the rules that result, and turn them into code.
If you insist on asking questions here, then at least LISTEN to the responses that you receive. Follow-up questions should include CODE that demonstrates two things: that you have absorbed the previous response and that you have made some additional progress which has led you to a new problem. (Or you don't understand the response and need a particular aspect clarified.)
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
···
On Mar 3, 2009, at 11:55 PM, Salil Gaikwad wrote:
i found solution to this problem i don't know it's correct way or not
neither how to do it programmatically.......
my problem is i am unable to read data correctly when my data-fields
are as follows
"abc", "sdfds "string"ddsfdsf", "xyz", "pqr"
it gives me error illegal file format at above line.
but when i open my file in Excel and then save it and close it,my data
look like this....
abc, "sdfds string""ddsfdsf""", xyz, pqr
thogh i don't get data i desired but it also not giving me error illegal
file format.
as above data is an exceptional case but due to it i can't read my whole
file so if i get some manipulated data for such an exceptional case it's
ok.
my question is ,is it possible using rails?