Ruby on Rails
Friday, June 15, 2018
On Friday, June 15, 2018 at 12:02:46 AM UTC-4, Hassan Schroeder wrote:
On Thu, Jun 14, 2018 at 4:09 PM, fugee ohu <fuge...@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.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote
So then right, this isn't the desired result
# of fields: 4
# of fields: 3
I tried adding more backslashes to 'barking\, all night' barking\\, barking\\\, barking \\\\, none of them got different results they all said 4 and 3
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/fc544146-1a05-41bb-9227-b0c0742565bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment