红宝石 |字符串 end_with?方法
end_with?是 Ruby 中的 String 类方法,用于检查指定的字符串是否以给定的后缀之一结尾。
Syntax: str.end_with?
Parameters: Here, str is the given string.
Returns: true if it matches otherwise return false.
示例 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