Reading CSV files with Ruby 1.9 -


i have csv file called test.csv this:

id     name               quantity  1     warehouse_name     4 

i can read name field this:

require 'csv' csv = csv.read('test.csv', :headers=>true) p csv['name'] 

suppose have 300 items on name field, , want grab unique names, because of them repeat.

how can tell if exist?

the results of csv['name'] array of strings, can treat other array of strings.

>> array = csv['name'] => ["mark", "betty", "mark", "jane", "fred", "jane"] >> array.uniq => ["mark", "betty", "jane", "fred"] 

refer docs array , enumerable more information.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -