红宝石 |字符串 delete_suffix 方法
delete_suffix是 Ruby 中的 String 类方法,用于返回给定字符串的副本,其中删除了尾随后缀。
Syntax: str.delete_suffix
Parameters: Here, str is the given string.
Returns: A copy of the given string with trailing suffix deleted.
示例 1:
# Ruby program to demonstrate
# the delete_suffix method
# Taking a string and
# using the method
puts "Ruby".delete_suffix("by")
puts "Class".delete_suffix("s")
输出:
Ru
Clas
示例 2:
# Ruby program to demonstrate
# the delete_suffix method
# Taking a string and
# using the method
puts "Sample".delete_suffix("pl")
puts "Input".delete_suffix("ut")
输出:
Sample
Inp