On Wed, Sep 16, 2009 at 11:06 PM, prashanth hiremath
<[email protected]> wrote:
> HiDestinationID^Name^City^StateProvince^Country^Latitude^Longitude^Type
> {B75F49C9-7B62-44E7-92FE-0A7F0CCEDF14}^ Sardinia de Galdar Beach^Gran
> Canary^ES^28.151890^-15.696225^2
> So that my code is
> dataArray= Array.new
> n = 0
> File.new("data.csv").each_line do |line|
> line.chomp!
> dataArray[n] = line.split(',')
> n += 1
> end
> i=0
> while(i < dataArray.length)
> puts "First: #{dataArray[i][0]}"
> i=i+1
> end
> But this code wotks to display all the fields
No kidding. Could that have anything to do with splitting your input
on ',' when there are no commas in the line at all? :-)
Your code is also very un-rubyish. A more idiomatic approach:
lines = []
File.new("data.csv").each_line { |line| lines << line.chomp!.split("^") }
lines.each { |line| puts "First: #{line[0]}" }
FWIW,
--
Hassan Schroeder ------------------------ [email protected]
twitter: @hassan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---