キーワード
- % (12)
- + (12)
- == (12)
- === (12)
- [] (72)
- []= (12)
- byteindex (3)
- byterindex (3)
- bytes (24)
- bytesize (12)
- byteslice (36)
- casecmp? (9)
- chars (12)
- codepoints (12)
- dump (12)
-
each
_ byte (24) -
each
_ char (12) -
each
_ codepoint (12) -
each
_ grapheme _ cluster (8) - empty? (12)
- encode (36)
-
end
_ with? (12) - eql? (12)
- getbyte (12)
-
grapheme
_ clusters (8) - gsub (48)
- gsub! (48)
- include? (12)
- intern (12)
- iseuc (12)
- match (12)
- match? (9)
- next (12)
- next! (12)
- oct (12)
- scan (24)
- scrub (36)
- scrub! (36)
- setbyte (12)
- slice (72)
- slice! (12)
- split (19)
-
start
_ with? (12) - sub (36)
- sub! (36)
- succ (12)
- succ! (12)
- sum (12)
-
to
_ i (12) -
to
_ sym (12) -
unicode
_ normalized? (11) - unpack (12)
- unpack1 (9)
- upto (12)
-
valid
_ encoding? (12)
検索結果
先頭5件
-
String
# []=(substr , val) (30145.0) -
文字列中の substr に一致する最初の部分文字列を文字列 val で置き換えます。
...文字列中の substr に一致する最初の部分文字列を文字列 val で置き換えます。
@param substr 置き換えたい部分文字列のパターンを示す文字列
@param val 指定範囲の部分文字列と置き換える文字列
@return val を返します。
@r......aise IndexError self が部分文字列 substr を含まない場合に発生します。
//emlist[例][ruby]{
buf = "string"
buf["trin"] = "!!"
p buf # => "s!!g"
buf = "string"
buf["nosuchstring"] = "!!" # IndexError
//}... -
String
# codepoints {|codepoint| block } -> self (30144.0) -
文字列の各コードポイントの配列を返します。(self.each_codepoint.to_a と同じです)
...ist[例][ruby]{
#coding:UTF-8
"hello わーるど".codepoints
# => [104, 101, 108, 108, 111, 32, 12431, 12540, 12427, 12393]
//}
ブロックが指定された場合は String#each_codepoint と同じように動作します。
Ruby 2.6 までは deprecated の警告が出ますが、Ruby 2.7 で......警告は削除されました。
@see String#each_codepoint... -
String
# each _ grapheme _ cluster {|grapheme _ cluster| block } -> self (30132.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
# unicode _ normalized?(form = :nfc) -> bool (30132.0) -
self が引数 form で指定された正規化形式で Unicode 正規化された文字列か どうかを返します。
...す。省略した場合は :nfc になります。
@raise Encoding::CompatibilityError self が Unicode 文字列ではない場合
に発生します。
//emlist[例][ruby]{
"a\u0300".unicode_normalized? # => false
"a\u0300".unicode_normalized?(:n......=> true
"\u00E0".unicode_normalized? # => true
"\u00E0".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 (30126.0) -
大文字小文字の違いを無視し文字列を比較します。 文字列が一致する場合には true を返し、一致しない場合には false を返します。
...します。
@param other self と比較する文字列
//emlist[例][ruby]{
"abcdef".casecmp?("abcde") #=> false
"aBcDeF".casecmp?("abcdef") #=> true
"abcdef".casecmp?("abcdefg") #=> false
"abcdef".casecmp?("ABCDEF") #=> true
"\u{e4 f6 fc}".casecmp?("\u{c4 d6 dc}") #=> true
//}
ni......l は文字列のエンコーディングが非互換の時に返されます。
//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 (30126.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
# each _ char {|cstr| block } -> self (30120.0) -
文字列の各文字に対して繰り返します。
...文字列の各文字に対して繰り返します。
たとえば、
//emlist[][ruby]{
"hello世界".each_char {|c| print c, ' ' }
//}
は次のように出力されます。
h e l l o 世 界
@see String#chars... -
String
# each _ codepoint {|codepoint| block } -> self (30120.0) -
文字列の各コードポイントに対して繰り返します。
...の各コードポイントに対して繰り返します。
UTF-8/UTF-16(BE|LE)/UTF-32(BE|LE) 以外のエンコーディングに対しては
各文字のバイナリ表現由来の値になります。
//emlist[例][ruby]{
#coding:UTF-8
"hello わーるど".each_codepoint.to_a
# => [104, 101, 1......08, 108, 111, 32, 12431, 12540, 12427, 12393]
"hello わーるど".encode('euc-jp').each_codepoint.to_a
# => [104, 101, 108, 108, 111, 32, 42223, 41404, 42219, 42185]
//}
@see String#codepoints... -
String
# match(regexp , pos = 0) {|m| . . . } -> object (30120.0) -
regexp.match(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match を参照してください。
...egexp のみの場合][ruby]{
'hello'.match('(.)\1') # => #<MatchData "ll" 1:"l">
'hello'.match('(.)\1')[0] # => "ll"
'hello'.match(/(.)\1/)[0] # => "ll"
'hello'.match('xx') # => nil
//}
//emlist[例: regexp, pos を指定した場合][ruby]{
'hoge hige hege bar'.match('h.ge', 0)...... 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, Symb... -
String
# unpack1(format) -> object (30120.0) -
formatにしたがって文字列をデコードし、展開された1つ目の値を返します。 unpackは配列を返しますがunpack1は配列の1つ目の要素のみを返します。
...って文字列をデコードし、展開された1つ目の値を返します。
unpackは配列を返しますがunpack1は配列の1つ目の要素のみを返します。
//emlist[例][ruby]{
"ABC".unpack1("C*") # => 65
"ABC".unpack("C*") # => [65, 66, 67]
//}
@see String#unpack, Array#pack... -
String
# sum(bits = 16) -> Integer (30114.0) -
文字列の bits ビットのチェックサムを計算します。
...文字列の bits ビットのチェックサムを計算します。
以下と同じです。
//emlist[][ruby]{
def sum(bits)
sum = 0
each_byte {|c| sum += c }
return 0 if sum == 0
sum & ((1 << bits) - 1)
end
//}
例えば以下のコードで UNIX System V の
sum(1) コマンドと同......じ値が得られます。
//emlist[例][ruby]{
sum = 0
ARGF.each_line do |line|
sum += line.sum
end
sum %= 65536
//}
@param bits チェックサムのビット数...