るりまサーチ

最速Rubyリファレンスマニュアル検索!
33件ヒット [1-33件を表示] (0.027秒)
トップページ > クエリ:Array[x] > クエリ:CSV[x] > クエリ:fields[x]

別のキーワード

  1. array fill
  2. array sample
  3. array []
  4. array fetch
  5. array slice

ライブラリ

クラス

検索結果

CSV (38406.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
_string = CSV.generate do |csv|
csv
<< ["row", "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"]
//}...
...omes when generating CSV into a String with an Encoding
that is not ASCII compatible. There's no existing data for CSV to use to
prepare itself and thus you will probably need to manually specify the desired
Encoding for most of those cases. It will try to guess using the fields in a
row of output...

CSV::Row#fields(*headers_and_or_indices) -> Array (21233.0)

与えられた引数に対応する値の配列を返します。

...与えられた引数に対応する値の配列を返します。

要素の探索に CSV::Row.field を使用しています。

@param headers_and_or_indices ヘッダの名前かインデックスか Range
のインスタンスか第 1 要素がヘッダの名前...
...るこ
とができます。

@return 引数を与えなかった場合は全ての要素を返します。

require 'csv'
csv
= CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
row = table.first
row.values_at("a", 1, 2..3) # => ["1", "2", "3", nil]...

CSV::Row#values_at(*headers_and_or_indices) -> Array (6133.0)

与えられた引数に対応する値の配列を返します。

...与えられた引数に対応する値の配列を返します。

要素の探索に CSV::Row.field を使用しています。

@param headers_and_or_indices ヘッダの名前かインデックスか Range
のインスタンスか第 1 要素がヘッダの名前...
...るこ
とができます。

@return 引数を与えなかった場合は全ての要素を返します。

require 'csv'
csv
= CSV.new("a,b,c\n1,2,3", headers: true)
table = csv.read
row = table.first
row.values_at("a", 1, 2..3) # => ["1", "2", "3", nil]...