11件ヒット
[1-11件を表示]
(0.039秒)
検索結果
先頭1件
-
CSV (14.0)
-
このクラスは CSV ファイルやデータに対する完全なインターフェイスを提供します。
...は CSV ファイルやデータに対する完全なインターフェイスを提供します。
=== 読み込み
//emlist[][ruby]{
require "csv"
csv_text = <<~CSV_TEXT
Ruby,1995
Rust,2010
CSV_TEXT
IO.write "sample.csv", csv_text
# ファイルから一行ずつ
CSV.foreach("sample.csv")......つ
CSV.parse(csv_text) do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2010"]
# 文字列から一度に
p CSV.parse(csv_text)
# => [["Ruby", "1995"], ["Rust", "2010"]]
//}
=== 書き込み
//emlist[][ruby]{
require 'csv'
# ファイルへ書き込み
CSV.open("path/to/file.csv", "wb"......objects
passed into CSV have the proper Encoding set and everything should just work.
CSV methods that allow you to open IO objects (CSV::foreach(), CSV::open(),
CSV::read(), and CSV::readlines()) do allow you to specify the Encoding.
One minor exception comes when generating CSV into a String with...