31件ヒット
[1-31件を表示]
(0.008秒)
別のキーワード
検索結果
先頭3件
-
String
# split(sep = $ ; , limit = 0) -> [String] (13.0) -
第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。
...列にマッチする場合は 1 文字に分割][ruby]{
p 'hi there'.split(/\s*/).join(':') # => "h:i:t:h:e:r:e"
//}
//emlist[文字列全体を 1 文字ずつに分割する例][ruby]{
p 'hi there'.split(//).join(':') # => "h:i: :t:h:e:r:e"
//}
//emlist[limit == 0 だと制限なく分割......、結果の配列末尾に含まれる空文字列が取り除かれている。
p " a b ".split(' ', 0) # => ["a", "b"]
# limit == 1 の場合は元の文字列がそのまま含まれる。
p " a b ".split(' ', 1) # => [" a b "]
//}
@see String#partition, String#rpartition... -
String
# split(sep = $ ; , limit = 0) {|s| . . . } -> self (13.0) -
第 1 引数 sep で指定されたセパレータによって文字列を limit 個まで分割し、 結果を文字列の配列で返します。 ブロックを指定すると、配列を返す代わりに分割した文字列で ブロックを呼び出します。
...列にマッチする場合は 1 文字に分割][ruby]{
p 'hi there'.split(/\s*/).join(':') # => "h:i:t:h:e:r:e"
//}
//emlist[文字列全体を 1 文字ずつに分割する例][ruby]{
p 'hi there'.split(//).join(':') # => "h:i: :t:h:e:r:e"
//}
//emlist[limit == 0 だと制限なく分割......、結果の配列末尾に含まれる空文字列が取り除かれている。
p " a b ".split(' ', 0) # => ["a", "b"]
# limit == 1 の場合は元の文字列がそのまま含まれる。
p " a b ".split(' ', 1) # => [" a b "]
//}
@see String#partition, String#rpartition... -
String
# unpack(template) -> Array (13.0) -
Array#pack で生成された文字列を テンプレート文字列 template にしたがってアンパックし、 それらの要素を含む配列を返します。
...@param template pack テンプレート文字列
@return オブジェクトの配列
以下にあげるものは、Array#pack、String#unpack
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
を続けることができます......!<: little endian signed long
//}
=== 各テンプレート文字の説明
説明中、Array#pack と String#unpack で違いのあるものは `/' で区切って
「Array#pack の説明 / String#unpack の説明」としています。
: a
ASCII文字列(ヌル文字を詰める/後続する......98, 121].pack("c*") # => "Ruby"
s = ""
[82, 117, 98, 121].each {|c| s << c}
s # => "Ruby"
[82, 117, 98, 121].collect {|c| sprintf "%c", c}.join # => "Ruby"
[82, 117, 98, 121].inject("") {|s, c| s << c} # => "Ruby"
//}
: 文字列を数値(文字コード)の配列に変換する例
/......m template pack テンプレート文字列
@return オブジェクトの配列
以下にあげるものは、Array#pack、String#unpack、String#unpack1
のテンプレート文字の一覧です。テンプレート文字は後に「長さ」を表す数字
を続けることがで...