るりまサーチ

最速Rubyリファレンスマニュアル検索!
69件ヒット [1-69件を表示] (0.251秒)

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin []
  4. _builtin to_s
  5. _builtin each

クラス

キーワード

検索結果

String#split(sep = $;, limit = 0) -> [String] (26219.0)

第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。 ブロックを指定すると、配列を返す代わりに分割した文字列で ブロックを呼び出します。

...][ruby]{
p " a \t b \n c".split(/\s+/) # => ["", "a", "b", "c"]

p " a \t b \n c".split(nil) # => ["a", "b", "c"]
p " a \t b \n c".split(' ') # => ["a", "b", "c"] # split(nil) と同じ
p " a \t b \n c".split # => ["a", "b", "c"] # split(nil) と同じ
//}

//emlist[...
...'.split(/([-,])/) # => ["1", "-", "10", ",", "20"]
//}

//emlist[正規表現が空文字列にマッチする場合は 1 文字に分割][ruby]{
p 'hi there'.split(/\s*/).join(':') # => "h:i:t:h:e:r:e"
//}

//emlist[文字列全体を 1 文字ずつに分割する例][ruby]{
p 'hi there'.split(/...
...,,,".split(/,/, 0) # => ["a", "b", "c"]
//}

//emlist[limit 省略時は 0 と同じ (最もよく使われるパターン)][ruby]{
p "a,b,c,,,".split(/,/) # => ["a", "b", "c"]
//}

//emlist[正の limit 使用例][ruby]{
p "a,b,c,d,e".split(/,/, 1) # => ["a,b,c,d,e"]
p "a,b,c,d,e".split(/,/...

String#split(sep = $;, limit = 0) {|s| ... } -> self (26219.0)

第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。 ブロックを指定すると、配列を返す代わりに分割した文字列で ブロックを呼び出します。

...][ruby]{
p " a \t b \n c".split(/\s+/) # => ["", "a", "b", "c"]

p " a \t b \n c".split(nil) # => ["a", "b", "c"]
p " a \t b \n c".split(' ') # => ["a", "b", "c"] # split(nil) と同じ
p " a \t b \n c".split # => ["a", "b", "c"] # split(nil) と同じ
//}

//emlist[...
...'.split(/([-,])/) # => ["1", "-", "10", ",", "20"]
//}

//emlist[正規表現が空文字列にマッチする場合は 1 文字に分割][ruby]{
p 'hi there'.split(/\s*/).join(':') # => "h:i:t:h:e:r:e"
//}

//emlist[文字列全体を 1 文字ずつに分割する例][ruby]{
p 'hi there'.split(/...
...,,,".split(/,/, 0) # => ["a", "b", "c"]
//}

//emlist[limit 省略時は 0 と同じ (最もよく使われるパターン)][ruby]{
p "a,b,c,,,".split(/,/) # => ["a", "b", "c"]
//}

//emlist[正の limit 使用例][ruby]{
p "a,b,c,d,e".split(/,/, 1) # => ["a,b,c,d,e"]
p "a,b,c,d,e".split(/,/...

String#split(sep = $;, limit = 0) -> [String] (26218.0)

第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。

...][ruby]{
p " a \t b \n c".split(/\s+/) # => ["", "a", "b", "c"]

p " a \t b \n c".split(nil) # => ["a", "b", "c"]
p " a \t b \n c".split(' ') # => ["a", "b", "c"] # split(nil) と同じ
p " a \t b \n c".split # => ["a", "b", "c"] # split(nil) と同じ
//}

//emlist[...
...'.split(/([-,])/) # => ["1", "-", "10", ",", "20"]
//}

//emlist[正規表現が空文字列にマッチする場合は 1 文字に分割][ruby]{
p 'hi there'.split(/\s*/).join(':') # => "h:i:t:h:e:r:e"
//}

//emlist[文字列全体を 1 文字ずつに分割する例][ruby]{
p 'hi there'.split(/...
...,,,".split(/,/, 0) # => ["a", "b", "c"]
//}

//emlist[limit 省略時は 0 と同じ (最もよく使われるパターン)][ruby]{
p "a,b,c,,,".split(/,/) # => ["a", "b", "c"]
//}

//emlist[正の limit 使用例][ruby]{
p "a,b,c,d,e".split(/,/, 1) # => ["a,b,c,d,e"]
p "a,b,c,d,e".split(/,/...

Array#pack(template) -> String (8015.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...換する例
//emlist[][ruby]{
"61 62 63 64 65 66".delete(' ').lines.pack('H*').unpack('C*')
# => [97, 98, 99, 100, 101, 102]

"61 62 63 64 65 66".split.collect {|c| c.hex}
# => [97, 98, 99, 100, 101, 102]
//}

: バイナリと16進数のpackでは長さ指定は生成されるバイト数ではな...
...ress_list = Socket.gethostbyname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"

"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}

: sockaddr_in 構造体
//emlist[][ruby]{
require 'socket'
[Socket::AF_INET,
So...

Array#pack(template, buffer: String.new) -> String (8015.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...換する例
//emlist[][ruby]{
"61 62 63 64 65 66".delete(' ').lines.pack('H*').unpack('C*')
# => [97, 98, 99, 100, 101, 102]

"61 62 63 64 65 66".split.collect {|c| c.hex}
# => [97, 98, 99, 100, 101, 102]
//}

: バイナリと16進数のpackでは長さ指定は生成されるバイト数ではな...
...ress_list = Socket.gethostbyname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"

"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}

: sockaddr_in 構造体
//emlist[][ruby]{
require 'socket'
[Socket::AF_INET,
So...

絞り込み条件を変える

String#unpack(template) -> Array (8015.0)

Array#pack で生成された文字列を テンプレート文字列 template にしたがってアンパックし、 それらの要素を含む配列を返します。

...換する例
//emlist[][ruby]{
"61 62 63 64 65 66".delete(' ').lines.pack('H*').unpack('C*')
# => [97, 98, 99, 100, 101, 102]

"61 62 63 64 65 66".split.collect {|c| c.hex}
# => [97, 98, 99, 100, 101, 102]
//}

: バイナリと16進数のpackでは長さ指定は生成されるバイト数ではな...
...ress_list = Socket.gethostbyname("localhost")
address_list.find {|address| address.size == 4 }.unpack("C4").join(".")
# => "127.0.0.1"

"127.0.0.1".split(".").collect {|c| c.to_i}.pack("C4")
# => "\x7F\x00\x00\x01"
//}

: sockaddr_in 構造体
//emlist[][ruby]{
require 'socket'
[Socket::AF_INET,
So...

String#partition(sep) -> [String, String, String] (8009.0)

セパレータ sep が最初に登場する部分で self を 3 つに分割し、 [最初のセパレータより前の部分, セパレータ, それ以降の部分] の 3 要素の配列を返します。

...@param sep セパレータを表す文字列か正規表現を指定します。

//emlist[例][ruby]{
p "axaxa".partition("x") # => ["a", "x", "axa"]
p "aaaaa".partition("x") # => ["aaaaa", "", ""]
p "aaaaa".partition("") # => ["", "", "aaaaa"]
//}

@see String#rpartition, String#split...

String#rpartition(sep) -> [String, String, String] (8009.0)

セパレータ sep が最後に登場する部分で self を 3 つに分割し、 [最後のセパレータより前の部分, セパレータ, それ以降の部分] の 3 要素の配列を返します。

...と第 2 要素が空文字列になります。

@param sep セパレータを表す文字列か正規表現を指定します。

//emlist[例][ruby]{
p "axaxa".rpartition("x") # => ["axa", "x", "a"]
p "aaaaa".rpartition("x") # => ["", "", "aaaaa"]
//}

@see String#partition, String#split...