44件ヒット
[1-44件を表示]
(0.050秒)
検索結果
先頭4件
-
Array
# to _ csv(**options) -> String (18237.0) -
CSV.generate_line(self, options) と同様です。
...tions) と同様です。
Array オブジェクトを 1 行の CSV 文字列に変換するためのショートカットです。
@param options CSV.generate_line と同様のオプションを指定します。
//emlist[][ruby]{
require 'csv'
p [1, 'Matz', :Ruby, Date.new(1965, 4, 14)].to_csv......# => "1,Matz,Ruby,1965-04-14\n"
p [1, 'Matz', :Ruby, Date.new(1965, 4, 14)].to_csv(col_sep: ' ', row_sep: "\r\n") # => "1 Matz Ruby 1965-04-14\r\n"
//}
@see CSV.generate_line......, 4, 14)].to_csv(col_sep: ' ', row_sep: "\r\n") # => "1 Matz Ruby 1965-04-14\r\n"
//}
Ruby 3.0 (CSV 3.1.9) から、次のオプションが使えるようになりました。
//emlist[][ruby]{
require 'csv'
puts [1, nil].to_csv # => 1,
puts [1, nil].to_csv(write_nil......_value: "N/A") # => 1,N/A
puts [2, ""].to_csv # => 2,""
puts [2, ""].to_csv(write_empty_value: "BLANK") # => 2,BLANK
//}
@see CSV.generate_line... -
CSV
:: Table # to _ csv(options = Hash . new) -> String (18213.0) -
CSV の文字列に変換して返します。
...ションに :write_headers =>
false を指定するとヘッダを出力しません。
//emlist[][ruby]{
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
p table.to_csv # => "a,b,c\n1,2,3\n"
p table.to_csv(write_headers: false) # => "1,2,3\n"
//}... -
CSV
:: Table # to _ s(options = Hash . new) -> String (3113.0) -
CSV の文字列に変換して返します。
...ションに :write_headers =>
false を指定するとヘッダを出力しません。
//emlist[][ruby]{
require 'csv'
csv = CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
p table.to_csv # => "a,b,c\n1,2,3\n"
p table.to_csv(write_headers: false) # => "1,2,3\n"
//}... -
CSV (36.0)
-
このクラスは 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") do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2......"of", "CSV", "data"]
csv << ["another", "row"]
# ...
end
//}
=== 一行変換
//emlist[][ruby]{
require 'csv'
csv_string = ["CSV", "data"].to_csv # => "CSV,data"
csv_array = "CSV,String".parse_csv # => ["CSV", "String"]
//}
=== ショートカット
//emlist[][ruby]{
require 'csv'
CS......<< %w{my data here} } # to $stderr
//}
=== CSV と文字エンコーディング (M17n or Multilingualization)
This new CSV parser is m17n savvy. The parser works in the Encoding of the IO
or String object being read from or written to. Your data is never transcoded
(unless you ask Ruby to tran...