Wiki » Historique » Version 1
Jonathan Schaeffer, 29/10/2015 13:50
1 | 1 | Jonathan Schaeffer | h1. Wiki |
---|---|---|---|
2 | |||
3 | |||
4 | h2. astuces : ouverture d'un CSV non UTF-8 |
||
5 | |||
6 | <pre> |
||
7 | 2.1.2 :001 > require 'csv' |
||
8 | => true |
||
9 | 2.1.2 :002 > handler = open('/home/schaeffer/tmp/exemple.csv') |
||
10 | => #<File:/home/schaeffer/tmp/exemple.csv> |
||
11 | 2.1.2 :003 > csv_string = handler.read.encode!("UTF-8", invalid: :replace) |
||
12 | 2.1.2 :004 > csv = CSV.parse csv_string, col_sep: ";", headers: true |
||
13 | => #<CSV::Table mode:col_or_row row_count:8641> |
||
14 | |||
15 | </pre> |