22件ヒット
[1-22件を表示]
(0.016秒)
検索結果
-
String
# parse _ csv(**options) -> [String] (24296.0) -
CSV.parse_line(self, options) と同様です。
...CSV.parse_line(self, options) と同様です。
1 行の CSV 文字列を、文字列の配列に変換するためのショートカットです。
@param options CSV.new と同様のオプションを指定します。
//emlist[][ruby]{
require "csv"
p "Matz,Ruby\n".parse_csv......|Ruby\r\n".parse_csv(col_sep: '|', row_sep: "\r\n") # => ["Matz", "Ruby"]
//}
Ruby 2.6 (CSV 3.0.2) から、次のオプションが使えるようになりました。
//emlist[][ruby]{
require 'csv'
p "1,,3\n".parse_csv # => ["1", nil, "3"]
p "1,,3\n".parse_csv(nil_value......: Float::NAN) # => ["1", NaN, "3"]
//}
@see CSV.new, CSV.parse_line......"]
//}
Ruby 2.7 (CSV 3.1.2) から、次のオプションが使えるようになりました。
//emlist[][ruby]{
require 'csv'
p "Matz, Ruby\n".parse_csv # => ["Matz", " Ruby"]
p "Matz, Ruby\n".parse_csv(strip: true) # => ["Matz", "Ruby"]
//}
@see CSV.new, CSV.parse_line... -
CSV (24.0)
-
このクラスは CSV ファイルやデータに対する完全なインターフェイスを提供します。
...sample.csv")
# => [["Ruby", "1995"], ["Rust", "2010"]]
# 文字列から一行ずつ
CSV.parse(csv_text) do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2010"]
# 文字列から一度に
p CSV.parse(csv_text)
# => [["Ruby", "1995"], ["Rust", "2010"]]
//}
=== 書き込み
//emlist[][rub......# ...
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'
CSV { |csv_out| csv_out << %w{my data here......17n 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 transcode it for you) and will literally be parsed in
the Encoding it is in. Thus CSV wi...