📜  红宝石 |字符串 end_with?方法

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

红宝石 |字符串 end_with?方法

end_with?是 Ruby 中的 String 类方法,用于检查指定的字符串是否以给定的后缀之一结尾。

示例 1:

# Ruby program to demonstrate 
# the end_with? method 
       
# Taking a string and 
# using the method
puts "Ruby".end_with?("by") 
puts "String".end_with?("ab") 

输出:

true
false

示例 2:

# Ruby program to demonstrate 
# the end_with? method 
       
# Taking a string and 
# using the method
# returns true if one of
# the +suffixes+ matches.
puts "Sample".end_with?("ple", "sam")
puts "Program".end_with?("gr", "pro") 

输出:

true
false