# Re: Q about the FasterCSV

**URL:** <https://www.ruby-forum.com/t/re-q-about-the-fastercsv/94300>\
**Category:** Ruby\
**Created:** [April 28, 2006, 7:31am UTC](https://www.ruby-forum.com/t/re-q-about-the-fastercsv/94300 "2006-04-28T07:31:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [April 28, 2006, 7:31am UTC](https://www.ruby-forum.com/t/re-q-about-the-fastercsv/94300/1 "2006-04-28T07:31:16Z")

</div>

Gregory B. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] :

# I think both CSV and FasterCSV can do this. Same rules apply though,

# just different delimiters.

great! thanks, Greg.

kind regards -botp

---

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [May 9, 2006, 6:44am UTC](https://www.ruby-forum.com/t/re-q-about-the-fastercsv/94300/2 "2006-05-09T06:44:47Z")

</div>

## Why ‘a,"bc"d’ could not be parsed correctly in both FasterCSV and CSV libary. while “a,'bc’d” could be parsed into [[“a”, “'bc’d”]] successfully.

irb(main):001:0\> require ‘fastercsv’  
true  
irb(main):002:0\> FasterCSV.parse(“a,'bc’d”)  
[[“a”, “'bc’d”]]  
irb(main):003:0\> FasterCSV.parse(‘a,"bc"d’)  
FasterCSV::MalformedCSVError: Unclosed quoted field on line 1.  
from  
e:/ruby/lib/ruby/gems/1.8/gems/fastercsv-0.2.0/lib/faster\_csv.rb:1165:in  
`shift' from e:/ruby/lib/ruby/gems/1.8/gems/fastercsv-0.2.0/lib/faster_csv.rb:1090:in`shift’  
from  
e:/ruby/lib/ruby/gems/1.8/gems/fastercsv-0.2.0/lib/faster\_csv.rb:1040:in  
`each' from e:/ruby/lib/ruby/gems/1.8/gems/fastercsv-0.2.0/lib/faster_csv.rb:1051:in`read’  
from  
e:/ruby/lib/ruby/gems/1.8/gems/fastercsv-0.2.0/lib/faster\_csv.rb:815:in  
`parse’  
from (irb):3  
irb(main):004:0\>

---

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [May 9, 2006, 6:53am UTC](https://www.ruby-forum.com/t/re-q-about-the-fastercsv/94300/3 "2006-05-09T06:53:59Z")

</div>

On Tue, 9 May 2006, Eric L. wrote:

> Why ‘a,"bc"d’ could not be parsed correctly in both FasterCSV and CSV  
> libary. while  
> “a,'bc’d” could be parsed into [[“a”, “'bc’d”]] successfully.

it’s malformed. it should look like this:

jib:~ \> ruby -r csv -e’ CSV::Writer::generate(STDOUT){|c| c \<\< %w[ a  
“bc"d ]} ’  
a,”"“bc”“d”

“a,'bc’d” is correct

jib:~ \> ruby -r csv -e" CSV::Writer::generate(STDOUT){|c| c \<\< %w[ a  
'bc’d ]} "  
a,'bc’d

double quotes must be escaped if they are to be within a field.

regards.

-a

---

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [May 9, 2006, 7:06am UTC](https://www.ruby-forum.com/t/re-q-about-the-fastercsv/94300/4 "2006-05-09T07:06:13Z")

</div>

Eric L. wrote:

> ## Why ‘a,"bc"d’ could not be parsed correctly in both FasterCSV and CSV libary. while “a,'bc’d” could be parsed into [[“a”, “'bc’d”]] successfully.
> 
> irb(main):001:0\> require ‘fastercsv’  
> true  
> irb(main):002:0\> FasterCSV.parse(“a,'bc’d”)  
> [[“a”, “'bc’d”]]  
> irb(main):003:0\> FasterCSV.parse(‘a,"bc"d’)  
> FasterCSV::MalformedCSVError: Unclosed quoted field on line 1.

Here are the rules:

1. Commas (,) separate fields. (You can pick a different delimiter if  
you like.)
2. Double-quotes (") are used to quote fields. They must surround the  
entire field.
3. Double-quotes (") are used to escape double-quotes inside a field.

If you want to write [‘a’, ‘"bc"d’] as CSV, do this:  
a,""“bc”“d”

Cheers,  
Dave

---

<div class="post-metadata">

**Author:** ![PeSSSSaS\_Botp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecd19e/32.png) [@PeSSSSaS\_Botp](https://www.ruby-forum.com/u/PeSSSSaS_Botp)\
**Post date:** [May 9, 2006, 10:17am UTC](https://www.ruby-forum.com/t/re-q-about-the-fastercsv/94300/5 "2006-05-09T10:17:50Z")

</div>

Thanks for your patient and time, Dave

Finally I understand the rules of the CSV format by your clear  
explanatioon.  
I really appreciate your help
