📜  红宝石 |字符串删除后缀!方法

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

红宝石 |字符串删除后缀!方法

删除后缀!是 Ruby 中的 String 类方法,用于返回给定字符串的副本,如果没有进行任何更改,则删除尾随后缀或 nil。

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

输出:

Inp