📜  红宝石 |字符串包括?方法

📅  最后修改于: 2022-05-13 01:54:33.026000             🧑  作者: Mango

红宝石 |字符串包括?方法

包括?是 Ruby 中的 String 类方法,用于在给定字符串包含给定字符串或字符时返回 true。

示例 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