るりまサーチ

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

別のキーワード

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

ライブラリ

キーワード

検索結果

<< < ... 14 15 16 17 18 ... > >>

String#each_grapheme_cluster {|grapheme_cluster| block } -> self (30032.0)

文字列の書記素クラスタに対して繰り返します。

...

String
#each_char と違って、
Unicode Standard Annex #29 (https://unicode.org/reports/tr29/)
で定義された書記素クラスタに対して繰り返します。

//emlist[例][ruby]{
"a\u0300".each_char.to_a.size # => 2
"a\u0300".each_grapheme_cluster.to_a.size # => 1
//}

@see String#g...

String#index(pattern, pos = 0) -> Integer | nil (30032.0)

文字列のインデックス pos から右に向かって pattern を検索し、 最初に見つかった部分文字列の左端のインデックスを返します。 見つからなければ nil を返します。

...mlist[例][ruby]{
p "astrochemistry".index("str") # => 1
p "regexpindex".index(/e.*x/, 2) # => 3
p "character".index(?c) # => 0

p "foobarfoobar".index("bar", 6) # => 9
p "foobarfoobar".index("bar", -6) # => 9
//}

@see String#rindex
@see String#byteindex...

String#rstrip! -> self | nil (30032.0)

文字列の末尾にある空白文字を全て破壊的に取り除きます。 空白文字の定義は " \t\r\n\f\v\0" です。

...的に取り除きます。
空白文字の定義は " \t\r\n\f\v\0" です。

//emlist[例][ruby]{
str = " abc\n"
p str.rstrip! # => " abc"
p str # => " abc"

str = " abc \r\n\t\v\0"
p str.rstrip! # => " abc"
p str # => " abc"
//}

@see String#rstrip, String#lstrip...

String#strip! -> self | nil (30032.0)

先頭と末尾の空白文字を全て破壊的に取り除きます。 空白文字の定義は " \t\r\n\f\v\0" です。

...ったときは nil を返します。

//emlist[例][ruby]{
str = " abc\r\n"
p str.strip! #=> "abc"
p str #=> "abc"

str = "abc"
p str.strip! #=> nil
p str #=> "abc"

str = " \0 abc \0"
str.strip!
p str #=> "abc"
//}

@see String#strip, String#lstrip...

String#unicode_normalize!(form = :nfc) -> self (30032.0)

self を NFC、NFD、NFKC、NFKD のいずれかの正規化形式で Unicode 正規化し た文字列に置き換えます。

...に発生します。

//emlist[例][ruby]{
text = "a\u0300"
text.unicode_normalize!(:nfc)
text == "\u00E0" # => true
text.unicode_normalize!(:nfd)
text == "a\u0300" # => true
//}

@see String#unicode_normalize, String#unicode_normalized?...

絞り込み条件を変える

String#unicode_normalized?(form = :nfc) -> bool (30032.0)

self が引数 form で指定された正規化形式で Unicode 正規化された文字列か どうかを返します。

...Encoding::CompatibilityError self が Unicode 文字列ではない場合
に発生します。

//emlist[例][ruby]{
"a\u0300".unicode_normalized? # => false
"a\u0300".unicode_normalized?(:nfd) # => true
"\u00E0".unicode_normalized? # => true
"\u...
...00E0".unicode_normalized?(:nfd) # => false
"\xE0".force_encoding('ISO-8859-1').unicode_normalized?
# => Encoding::CompatibilityError raised
//}

@see String#unicode_normalize, String#unicode_normalize!...

String#casecmp?(other) -> bool | nil (30026.0)

大文字小文字の違いを無視し文字列を比較します。 文字列が一致する場合には true を返し、一致しない場合には false を返します。

...る場合には true を返し、一致しない場合には false を返します。

@param other self と比較する文字列

//emlist[例][ruby]{
"abcdef".casecmp?("abcde") #=> false
"aBcDeF".casecmp?("abcdef") #=> true
"abcdef".casecmp?("abcdefg") #=> false
"abcdef".casecmp?("ABCD...
...EF") #=> true
"\u{e4 f6 fc}".casecmp?("\u{c4 d6 dc}") #=> true
//}

nil は文字列のエンコーディングが非互換の時に返されます。

//emlist[][ruby]{
"\u{e4 f6 fc}".encode("ISO-8859-1").casecmp?("\u{c4 d6 dc}") #=> nil
//}

@see String#casecmp...

String#match?(regexp, pos = 0) -> bool (30026.0)

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

...正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。

//emlist[例][ruby]{
"Ruby".match?(/R.../) #=> true
"Ruby".match?(/R.../, 1) #=> false
"Ruby".match?(/P.../) #=> false
$& #=> nil
//}

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

String#[]=(regexp, name, val) (30025.0)

正規表現 regexp の name で指定した名前付きキャプチャにマッチする最初の 部分文字列を文字列 val で置き換えます。

...置き換えたい文字列

@return val を返します。

@raise IndexError name で指定した名前付きキャプチャが存在しない場合に発
生します。

//emlist[例][ruby]{
s = "FooBar"
s[/(?<foo>[A-Z]..)(?<bar>[A-Z]..)/, "foo"] = "Baz"
p s # => "BazBar"
//}...

String#[]=(regexp, nth, val) (30025.0)

正規表現 regexp の nth 番目の括弧にマッチする 最初の部分文字列を文字列 val で置き換えます。

...定範囲の部分文字列と置き換えたい文字列

@return val を返します。

@raise IndexError 正規表現がマッチしなかった場合に発生します。

//emlist[例][ruby]{
buf = "def exec(cmd)"
buf[/def\s+(\w+)/, 1] = "preprocess"
p buf # => "def preprocess(cmd)"
//}...

絞り込み条件を変える

String#gsub!(pattern, hash) -> self | nil (30025.0)

文字列中の pattern にマッチした部分をキーにして hash を引いた値へ破壊的に置き換えます。

...す。

@param pattern 置き換える文字列のパターン
@param hash 置き換える文字列を与えるハッシュ

//emlist[例][ruby]{
hash = {'b'=>'B', 'c'=>'C'}
str = "abcabc"
str.gsub!(/[bc]/){hash[$&]}
p str #=> "aBCaBC"

str = "abcabc"
str.gsub!(/[bc]/, hash)
p str #...
<< < ... 14 15 16 17 18 ... > >>