るりまサーチ

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

別のキーワード

  1. string []=
  2. string slice
  3. string slice!
  4. string []
  5. openssl utf8string

ライブラリ

キーワード

検索結果

<< < ... 3 4 5 6 7 ... > >>

String#each_byte {|byte| ... } -> self (36220.0)

文字列の各バイトに対して繰り返します。

...文字列の各バイトに対して繰り返します。

//emlist[例][ruby]{
"str".each_byte do |byte|
p byte
end
# => 115
# => 116
# => 114

"あ".each_byte do |byte|
p byte
end
# => 227
# => 129
# => 130
//}

@see String#bytes...

String#match(regexp, pos = 0) -> MatchData | nil (36220.0)

regexp.match(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match を参照してください。

...regexp.match(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match を参照してください。

//emlist[例: regexp のみの場合][ruby]{
'hello'.match('(.)\1') # => #<MatchData "ll" 1:"l">
'hello'.match('(.)\1...
...ll"
'hello'.match(/(.)\1/)[0] # => "ll"
'hello'.match('xx') # => nil
//}

//emlist[例: regexp, pos を指定した場合][ruby]{
'hoge hige hege bar'.match('h.ge', 0) # => #<MatchData "hoge">
'hoge hige hege bar'.match('h.ge', 1) # => #<MatchData "hige">
//}

//emlist[例: ブロ...
...ックを指定した場合][ruby]{
'hello'.match('(.)\1'){|e|"match #{$1}"} # => "match l"
'hello'.match('xx'){|e|"match #{$1}"} # マッチしないためブロックは実行されない
//}

@see Regexp#match, Symbol#match...

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

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

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

第 1 引数 sep は以下...
...が配列に含まれます。

第 2 引数 limit は以下のいずれかです。

: limit > 0
最大 limit 個の文字列に分割する
: limit == 0
分割個数制限はなしで、配列末尾の空文字列を取り除く
: limit < 0
分割個数の制限はなし

@param sep...
...param limit 分割する最大個数

@return ブロックを渡した場合は self、ブロックなしの場合は配列

//emlist[例][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(' ') #...

String#start_with?(*prefixes) -> bool (36204.0)

self の先頭が prefixes のいずれかであるとき true を返します。

... true を返します。

@param prefixes パターンを表す文字列または正規表現 (のリスト)

//emlist[例][ruby]{
"string".start_with?("str") # => true
"string".start_with?("ing") # => false
"string".start_with?("ing", "str") # => true
"string".start_with?(/\w...
.../) # => true
"string".start_with?(/\d/) # => false
//}

@see String#end_with?
@see String#delete_prefix, String#delete_prefix!...

String#end_with?(*strs) -> bool (36180.0)

self の末尾が strs のいずれかであるとき true を返します。

...strs のいずれかであるとき true を返します。

@param strs パターンを表す文字列 (のリスト)

//emlist[例][ruby]{
"string".end_with?("ing") # => true
"string".end_with?("str") # => false
"string".end_with?("str", "ing") # => true
//}

@see String#sta...
...rt_with?
@see String#delete_suffix, String#delete_suffix!...

絞り込み条件を変える

String#to_f -> Float (36174.0)

文字列を 10 進数表現と解釈して、浮動小数点数 Float に変換します。

...数 Float に変換します。

浮動小数点数とみなせなくなるところまでを変換対象とします。
途中に変換できないような文字列がある場合、それより先の文字列は無視されます。

//emlist[][ruby]{
p "-10".to_f # => -10.0
p "10e2".to_f # =>...
...1000.0
p "1e-2".to_f # => 0.01
p ".1".to_f # => 0.1

p "1_0_0".to_f # => 100.0 # 数値リテラルと同じように区切りに _ を使える
p " \n10".to_f # => 10.0 # 先頭の空白・改行は無視される
p "7xa.5".to_f # => 7.0
//}

以下の例は、先頭に浮動小数点数と...
...列のケースでも、0.0 を返します。

//emlist[][ruby]{
p "".to_f # => 0.0
p "nan".to_f # => 0.0
p "INF".to_f # => 0.0
p "-Inf".to_f # => 0.0
//}

変換後の Float が有限の値を取れないときは、Float::INFINITY を用います。
このとき、全ての警告を有...

String#to_i(base = 10) -> Integer (36174.0)

文字列を 10 進数表現された整数であると解釈して、整数に変換します。

...ist[例][ruby]{
p " 10".to_i # => 10
p "+10".to_i # => 10
p "-10".to_i # => -10

p "010".to_i # => 10
p "-010".to_i # => -10
//}

整数とみなせない文字があればそこまでを変換対象とします。
変換対象が空文字列であれば 0 を返します。

//emlist[...
...例][ruby]{
p "0x11".to_i # => 0
p "".to_i # => 0
//}

基数を指定することでデフォルトの 10 進以外に 2 〜 36 進数表現へ変換できます。
それぞれ Ruby の整数リテラルで使用可能なプリフィクスは無視されます。
また、base に 0 を指...
...gumentError が発生します。

//emlist[例][ruby]{
p "01".to_i(2) # => 1
p "0b1".to_i(2) # => 1

p "07".to_i(8) # => 7
p "0o7".to_i(8) # => 7

p "1f".to_i(16) # => 31
p "0x1f".to_i(16) # => 31

p "0b10".to_i(0) # => 2
p "0o10".to_i(0) # => 8
p "010".to_i(0) # => 8
p "0d10".to_i(...

String#capitalize!(*options) -> self | nil (36168.0)

文字列先頭の文字を大文字に、残りを小文字に破壊的に変更します。

...options オプションの詳細は String#downcase を参照してください。

@return capitalize! は self を変更して返しますが、
変更が起こらなかった場合は nil を返します。

//emlist[例][ruby]{
str = "foobar"
str.capitalize!
p str # => "Foobar"

str =...
..."fooBAR"
str.capitalize!
p str # => "Foobar"
//}

@see String#capitalize, String#upcase!,
String
#downcase!, String#swapcase!...

String#delete_suffix!(suffix) -> self | nil (36168.0)

self の末尾から破壊的に suffix を削除します。

...ます。

@return 削除した場合は self、変化しなかった場合は nil

//emlist[][ruby]{
"hello".delete_suffix!("llo") # => "he"
"hello".delete_suffix!("hel") # => nil
//}

@see String#chomp!
@see String#chop!
@see String#delete_prefix!
@see String#delete_suffix
@see String#end_with?...

String#oct -> Integer (36168.0)

文字列を 8 進文字列であると解釈して、整数に変換します。

...//emlist[例][ruby]{
p "10".oct # => 8
p "010".oct # => 8
p "8".oct # => 0
//}

oct は文字列の接頭辞 ("0", "0b", "0B", "0x", "0X") に応じて
8 進以外の変換も行います。

//emlist[例][ruby]{
p "0b10".oct # => 2
p "10".oct # => 8
p "010".oct # => 8
p "0x10".oct # => 1...
...//emlist[例][ruby]{
p "-010".oct # => -8
p "-0x10".oct # => -16
p "-0b10".oct # => -2

p "1_0_1x".oct # => 65
//}

@see String#hex, String#to_i, String#to_f,
Kernel.#Integer, Kernel.#Float

逆に、数値を文字列に変換するにはKernel.#sprintf,
String
#%, Integer#to_s を...

絞り込み条件を変える

String#append_as_bytes(*objects) -> self (36156.0)

引数で与えたオブジェクトをバイト列として、self に破壊的に連結します。

...st[例][ruby]{
s = "あ".b # => "\xE3\x81\x82"
s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
s.append_as_bytes("い") # => "\xE3\x81\x82\xE3\x81\x84"

# s << "い" では連結できない
s << "い" # => "incompatible character encodings: BINARY (ASCII-8BIT) and UT...
...F-8 (Encoding::CompatibilityError)
//}

//emlist[引数で整数を渡す例][ruby]{
t
= ""
t
.append_as_bytes(0x61) # => "a"
t
.append_as_bytes(0x3062) # => "ab"
//}

@see String#<<, String#concat...

String#capitalize! -> self | nil (36156.0)

文字列先頭の文字を大文字に、残りを小文字に変更します。 ただし、アルファベット以外の文字は位置に関わらず変更しません。

...@return capitalize! は self を変更して返しますが、
変更が起こらなかった場合は nil を返します。

//emlist[例][ruby]{
str = "foobar"
str.capitalize!
p str # => "Foobar"

str = "fooBAR"
str.capitalize!
p str # => "Foobar"
//}

@see String#capitalize, String#u...
...pcase!,
String
#downcase!, String#swapcase!...

String#end_with?(*strs) -> bool (36156.0)

self の末尾が strs のいずれかであるとき true を返します。

...strs のいずれかであるとき true を返します。

@param strs パターンを表す文字列 (のリスト)

//emlist[例][ruby]{
"string".end_with?("ing") # => true
"string".end_with?("str") # => false
"string".end_with?("str", "ing") # => true
//}

@see String#sta...
...rt_with?...
<< < ... 3 4 5 6 7 ... > >>