48件ヒット
[1-48件を表示]
(0.027秒)
別のキーワード
検索結果
-
CSV
# quote _ char -> String (18119.0) -
フィールドをクオートするのに使用する文字列を返します。
...フィールドをクオートするのに使用する文字列を返します。
//emlist[例][ruby]{
require "csv"
csv = CSV.new("header1,header2\nrow1_1,row1_2", quote_char: "'")
csv.quote_char # => "'"
//}
@see CSV.new... -
CSV (72.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", "2010"]
# ファイル......)
# => [["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[][ruby]{
require......e transcoding must take place, of course, to accomplish this multiencoding
support. For example, <tt>:col_sep</tt>, <tt>:row_sep</tt>, and
<tt>:quote_char</tt> must be transcoded to match your data. Hopefully this
makes the entire process feel transparent, since CSV's defaults should just
magicall... -
CSV
. new(data , options = Hash . new) -> CSV (24.0) -
このメソッドは CSV ファイルを読み込んだり、書き出したりするために String か IO のインスタンスをラップします。
...ing the document position to where it was before the
read ahead. This String will be transcoded into the data's Encoding before parsing.
: :quote_char
フィールドをクオートする文字を指定します。長さ 1 の文字列でなければなりません。
正しいダブルク......を指定すると CSV.parse_line を
使用してパースした結果をヘッダとして扱います。このとき、:col_sep, :row_sep, :quote_char
はこのインスタンスと同じものを使用します。この設定は CSV#shift
の返り値を配列のかわりに CSV::Row の......@raise CSV::MalformedCSVError 不正な CSV をパースしようとしたときに発生します。
//emlist[例: ファイルの読み込み][ruby]{
require "csv"
users =<<-EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS
File.write("test.c... -
CSV
# inspect -> String (12.0) -
ASCII 互換文字列で自身の情報を表したものを返します。
...ASCII 互換文字列で自身の情報を表したものを返します。
//emlist[例][ruby]{
require "csv"
csv = CSV.new("header1,header2\nrow1_1,row1_2")
csv.inspect # => "<#CSV io_type:StringIO encoding:UTF-8 lineno:0 col_sep:\",\" row_sep:\"\\n\" quote_char:\"\\\"\">"
//}...