Ruby on Rails Thursday, June 14, 2018

On Thu, Jun 14, 2018 at 4:09 PM, fugee ohu <fugee279@gmail.com> wrote:
> csv files have their commas pre-escaped so i don't have to worry about there
> being commas in data, i can just use the split function to read in?

Maybe.

-----------------------------------------------------------------------------------------
require 'csv'

csv_string = CSV.generate do |csv|
csv << ['dog', 'barking\, all night', 'woof\n']
csv << ['cat', 'meowing incessantly', 'meow\n']
end

csv_string.split("\n").each { |line| puts("# of fields:
#{line.split(',').length}\n") }
-----------------------------------------------------------------------------------------

Maybe not. 😀

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CACmC4yAm0evFp%3Dy5r6kJvP-0tqpPYM_T%2B-ODGUBkdop40PRMrQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment