キーワード
- == (1)
- === (1)
-
ascii
_ only? (1) - casecmp? (1)
- empty? (1)
-
end
_ with? (1) - eql? (1)
- include? (1)
- iseuc (1)
- isjis (1)
- issjis (1)
- isutf8 (1)
- match? (1)
-
start
_ with? (1) -
unicode
_ normalized? (1) -
valid
_ encoding? (1)
検索結果
先頭5件
-
String
# ==(other) -> bool (313.0) -
other が文字列の場合、String#eql? と同様に文字列の内容を比較します。
...other が文字列の場合、String#eql? と同様に文字列の内容を比較します。
other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false......st[例][ruby]{
stringlike = Object.new
def stringlike.==(other)
"string" == other
end
p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> false
def stringlike.to_str
raise
end
p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> true
//}
@see String#eql?... -
String
# ===(other) -> bool (313.0) -
other が文字列の場合、String#eql? と同様に文字列の内容を比較します。
...other が文字列の場合、String#eql? と同様に文字列の内容を比較します。
other が文字列でない場合、
other.to_str が定義されていれば
other == self の結果を返します。(ただし、 other.to_str は実行されません。)
そうでなければ false......st[例][ruby]{
stringlike = Object.new
def stringlike.==(other)
"string" == other
end
p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> false
def stringlike.to_str
raise
end
p "string".eql?(stringlike) #=> false
p "string" == stringlike #=> true
//}
@see String#eql?... -
String
# ascii _ only? -> bool (310.0) -
文字列がASCII文字のみで構成されている場合に true を返します。さもなくば false を返します。
文字列がASCII文字のみで構成されている場合に true を返します。さもなくば
false を返します。
例:
'abc123'.ascii_only? # => true
''.ascii_only? # => true
'日本語'.ascii_only? # => false
'日本語abc123'.ascii_only? # => false -
String
# casecmp?(other) -> bool | nil (310.0) -
大文字小文字の違いを無視し文字列を比較します。 文字列が一致する場合には true を返し、一致しない場合には false を返します。
...false
"abcdef".casecmp?("ABCDEF") #=> 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
# empty? -> bool (310.0) -
文字列が空 (つまり長さ 0) の時、真を返します。
文字列が空 (つまり長さ 0) の時、真を返します。
//emlist[例][ruby]{
"hello".empty? #=> false
" ".empty? #=> false
"".empty? #=> true
//} -
String
# end _ with?(*strs) -> bool (310.0) -
self の末尾が strs のいずれかであるとき true を返します。
...ずれかであるとき true を返します。
@param strs パターンを表す文字列 (のリスト)
//emlist[例][ruby]{
"string".end_with?("ing") # => true
"string".end_with?("str") # => false
"string".end_with?("str", "ing") # => true
//}
@see String#start_with?... -
String
# eql?(other) -> bool (310.0) -
文字列の内容が文字列 other の内容と等しいときに true を返します。 等しくなければ false を返します。
...します。
同一のオブジェクトかどうかを比較するわけではありません。
つまり、"string".eql?(str) という式を実行した場合には、
str が "string" という内容の文字列でありさえすれば常に true を返します。
同一のオブジェクト......場合は
String#casecmp? を使ってください。
Hash クラス内での比較に使われます。
@param other 任意のオブジェクト
@return true か false
//emlist[例][ruby]{
p "string".eql?("string") # => true
p "string".eql?("STRING") # => false
p "string".eql?("")......# => false
p "".eql?("string") # => false
p "string".eql?("str" + "ing") # => true (内容が同じなら true)
p "string".eql?("stringX".chop) # => true (内容が同じなら true)
//}
@see Hash, String#<=>, String#casecmp, String#==... -
String
# include?(substr) -> bool (310.0) -
文字列中に部分文字列 substr が含まれていれば真を返します。
文字列中に部分文字列 substr が含まれていれば真を返します。
@param substr 検索する文字列
//emlist[例][ruby]{
"hello".include? "lo" #=> true
"hello".include? "ol" #=> false
"hello".include? ?h #=> true
//} -
String
# iseuc -> bool (310.0) -
self が EUC-JP なバイト列として正当であるかどうかを判定します。
self が EUC-JP なバイト列として正当であるかどうかを判定します。
Kconv.#iseuc(self) と同じです。
//emlist[例][ruby]{
require 'kconv'
euc_str = "\
\xa5\xaa\xa5\xd6\xa5\xb8\xa5\xa7\xa5\xaf\xa5\xc8\xbb\xd8\xb8\xfe\
\xa5\xd7\xa5\xed\xa5\xb0\xa5\xe9\xa5\xdf\xa5\xf3\xa5\xb0\xb8\xc0\xb8\xec\
\x52\x75\x62\x79".force_encoding('EUC-JP')
... -
String
# isjis -> bool (310.0) -
self が ISO-2022-JP なバイト列として正当であるかどうかを判定します。
self が ISO-2022-JP なバイト列として正当であるかどうかを判定します。
Kconv.isjis(self) と同じです。 -
String
# issjis -> bool (310.0) -
self が Shift_JIS なバイト列として正当であるかどうかを判定します。
self が Shift_JIS なバイト列として正当であるかどうかを判定します。
Kconv.#issjis と同じです。 -
String
# isutf8 -> bool (310.0) -
self が UTF-8 なバイト列として正当であるかどうかを判定します。
self が UTF-8 なバイト列として正当であるかどうかを判定します。
Kconv.#isutf8(self) と同じです。 -
String
# match?(regexp , pos = 0) -> bool (310.0) -
regexp.match?(self, pos) と同じです。 regexp が文字列の場合は、正規表現にコンパイルします。 詳しくは Regexp#match? を参照してください。
regexp.match?(self, pos) と同じです。
regexp が文字列の場合は、正規表現にコンパイルします。
詳しくは Regexp#match? を参照してください。
//emlist[例][ruby]{
"Ruby".match?(/R.../) #=> true
"Ruby".match?(/R.../, 1) #=> false
"Ruby".match?(/P.../) #=> false
$& #=> nil
//}
@see Regexp#match?, Symbol#match? -
String
# start _ with?(*strs) -> bool (310.0) -
self の先頭が strs のいずれかであるとき true を返します。
...れかであるとき true を返します。
@param strs パターンを表す文字列 (のリスト)
//emlist[例][ruby]{
"string".start_with?("str") # => true
"string".start_with?("ing") # => false
"string".start_with?("ing", "str") # => true
//}
@see String#end_with?... -
String
# unicode _ normalized?(form = :nfc) -> bool (310.0) -
self が引数 form で指定された正規化形式で Unicode 正規化された文字列か どうかを返します。
...=> 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
# valid _ encoding? -> bool (310.0) -
文字列の内容が、現在のエンコーディングに照らしあわせて妥当であれば true を返します。さもなくば false を返します。
文字列の内容が、現在のエンコーディングに照らしあわせて妥当であれば
true を返します。さもなくば false を返します。
//emlist[例][ruby]{
"\xc2\xa1".force_encoding("UTF-8").valid_encoding? #=> true
"\xc2".force_encoding("UTF-8").valid_encoding? #=> false
"\x80".force_encoding("UTF-8").valid_encoding? #=> false
//}