るりまサーチ

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

別のキーワード

  1. _builtin |
  2. set |
  3. ipaddr |
  4. nilclass |
  5. trueclass |

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

CSV#col_sep -> String (18345.0)

カラム区切り文字列として使用する文字列を返します。

...返します。

//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

csv = CSV.new(users, headers: true, col_sep: "|")
csv.col_sep # => "|"
csv.first.to_a # => [["id", "1"], ["first name", "taro"], ["last...
...name", "tanaka"], ["age", "20"]]

csv = CSV.new(users, headers: true)
csv.col_sep # => ","
csv.first.to_a # => [["id|first name|last name|age", "1|taro|tanaka|20"]]
//}

@see CSV.new...

CSV.parse(str, options = Hash.new) {|row| ... } -> nil (285.0)

このメソッドは文字列を簡単にパースすることができます。 ブロックを与えた場合は、ブロックにそれぞれの行を渡します。 ブロックを省略した場合は、配列の配列を返します。

....parse(s, headers: true).each do |row|
p [row['first name'], row['age']]
end
# => ["taro", "20"]
# ["jiro", "18"]
//}

//emlist[例][ruby]{
require "csv"

csv = "id|first name|last name|age\n1|taro|tanaka|20\n2|jiro|suzuki|18"
CSV.parse(csv, col_sep: '|') do |row|
p [row[1], row[2]]
end
# =>...

CSV.new(data, options = Hash.new) -> CSV (238.0)

このメソッドは CSV ファイルを読み込んだり、書き出したりするために String か IO のインスタンスをラップします。

...きすることが
出来ないので、上書きしたい場合は必ずここで上書きするようにしてください。

: :col_sep
フィールドの区切り文字列を指定します。この文字列はパースする前にデータの
エンコーディングに変...
...manually if speed is important. Also
note that IO objects should be opened in binary mode on Windows if this
feature will be used as the line-ending translation can cause
problems with resetting the document position to where it was before the
read ahead. This String will be transcode...
...t[例: ファイルの読み込み][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.csv", users)

File.open("test.csv", "r") do |f|
csv = CSV.new(f, headers: true)
csv.class # => CSV
csv.firs...

CSV.parse(str, options = Hash.new) -> Array (185.0)

このメソッドは文字列を簡単にパースすることができます。 ブロックを与えた場合は、ブロックにそれぞれの行を渡します。 ブロックを省略した場合は、配列の配列を返します。

....parse(s, headers: true).each do |row|
p [row['first name'], row['age']]
end
# => ["taro", "20"]
# ["jiro", "18"]
//}

//emlist[例][ruby]{
require "csv"

csv = "id|first name|last name|age\n1|taro|tanaka|20\n2|jiro|suzuki|18"
CSV.parse(csv, col_sep: '|') do |row|
p [row[1], row[2]]
end
# =>...

CSV.generate_line(row, options = Hash.new) -> String (124.0)

このメソッドは一つの Array オブジェクトを CSV 文字列に変換するためのショートカットです。 複数行のCSVを扱う際はCSV#<<を使うとより高速です。

...コーディングを指定することができます。
:row_sep というキーの値には $/ がセットされます。

//emlist[例][ruby]{
require "csv"

taro = ['1', 'taro', 'tanaka', '20']
CSV.generate_line(taro, col_sep: '|') # => "1|taro|tanaka|20\n"
//}

@see CSV.new...

絞り込み条件を変える

CSV.parse_line(line, options = Hash.new) -> Array (124.0)

このメソッドは一行の CSV 文字列を配列に変換するためのショートカットです。

...す。

//emlist[例][ruby]{
require 'csv'

p CSV.parse_line("1,taro,tanaka,20")
# => ["1", "taro", "tanaka", "20"]

p CSV.parse_line("1|taro|tanaka|20", col_sep: '|')
# => ["1", "taro", "tanaka", "20"]

# 列をダブルクオートで囲むとその中にカンマや改行を含める事もでき...

CSV::Row#to_csv -> String (112.0)

自身を CSV な文字列として返します。ヘッダは使用しません。

...自身を CSV な文字列として返します。ヘッダは使用しません。

//emlist[例][ruby]{
require "csv"

row = CSV::Row.new(["header1", "header2"], [1, 2])
row.to_csv # => "1,2\n"
row.to_csv( {col_sep: "|", row_sep: "<br>"} ) # => "1|2<br>"
//}...

CSV::Row#to_s -> String (112.0)

自身を CSV な文字列として返します。ヘッダは使用しません。

...自身を CSV な文字列として返します。ヘッダは使用しません。

//emlist[例][ruby]{
require "csv"

row = CSV::Row.new(["header1", "header2"], [1, 2])
row.to_csv # => "1,2\n"
row.to_csv( {col_sep: "|", row_sep: "<br>"} ) # => "1|2<br>"
//}...

String#parse_csv(**options) -> [String] (112.0)

CSV.parse_line(self, options) と同様です。

...ます。

//emlist[][ruby]{
require "csv"

p "Matz,Ruby\n".parse_csv # => ["Matz", "Ruby"]
p "Matz|Ruby\r\n".parse_csv(col_sep: '|', row_sep: "\r\n") # => ["Matz", "Ruby"]
//}

Ruby 2.6 (CSV 3.0.2) から、次のオプションが使えるようになりました...

CSV (102.0)

このクラスは CSV ファイルやデータに対する完全なインターフェイスを提供します。

...行ずつ
CSV.foreach("sample.csv") do |row|
p row
end
# => ["Ruby", "1995"]
# ["Rust", "2010"]

# ファイルから一度に
p CSV.read("sample.csv")
# => [["Ruby", "1995"], ["Rust", "2010"]]

# 文字列から一行ずつ
CSV.parse(csv_text) do |row|
p row
end
# => ["Ruby", "1995"]
# ["...
...g the parser itself
into your Encoding.

Some 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 transparen...
...important to note that while all of CSV's core parser is now
Encoding agnostic, some features are not. For example, the built-in
converters will try to transcode data to UTF-8 before making conversions.
Again, you can provide custom converters that are aware of your Encodings to
avoid this translat...

絞り込み条件を変える

<< 1 2 > >>