Thursday, August 11, 2011

Ruby 1.8.7 CSV parser workaround

Apparently there is some kind of problem when using the CSV parser for particular text structures. I want able to determine the exact cause of this problem expect that for some csv structures, the parse process result in an error.

In my frustration I resorted to write my one parser that is implemented as following:

 def self.parse(text)
    rows=text.split("\r")
    res=[]
    rows.each{|row|
      res << row.split(",")
    }
    res
  end

And amazingly enough, that's what did the trick.

Independent on Sundays.




No comments:

Post a Comment

Please do not post spam on this blog, Spam sites will be reported to google.
thank you kindly.