红宝石 |字符串包括?方法
包括?是 Ruby 中的 String 类方法,用于在给定字符串包含给定字符串或字符时返回 true。
Syntax: str.include?
Parameters: Here, str is the given string.
Returns: true if the given string contains the given string or character otherwise false.
示例 1:
# Ruby program to demonstrate
# the include? method
# Taking a string and
# using the method
puts "Ruby".include? "by"
puts "String".include? "ui"
输出:
true
false
示例 2:
# Ruby program to demonstrate
# the include? method
# Taking a string and
# using the method
puts "Sample".include? "am"
puts "Input".include? "pt"
输出:
true
false