reading in from csv files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

reading in from csv files

fugee ohu
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?

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fa10fae0-cb85-4028-a126-896bbd365d79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading in from csv files

Hassan Schroeder-2
On Thu, Jun 14, 2018 at 4:09 PM, fugee ohu <[hidden email]> 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 ------------------------ [hidden email]
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: reading in from csv files

fugee ohu


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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="_Z1Nd_q2AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> 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 ------------------------ <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_Z1Nd_q2AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">hassan.s...@...
twitter: @hassan
Consulting Availability : Silicon Valley or remote

So then right, this isn't the desired result
# of fields: 4
# of fields: 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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5462611e-b785-49da-b68f-8e3081c6db8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading in from csv files

fugee ohu
In reply to this post by Hassan Schroeder-2


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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="_Z1Nd_q2AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> 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 ------------------------ <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_Z1Nd_q2AwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">hassan.s...@...
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 [hidden email].
To post to this group, send email to [hidden email].
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.