红宝石 |字符串删除前缀!方法
删除前缀!是 Ruby 中的 String 类方法,用于返回给定字符串的副本,其中前导前缀已删除,如果未进行任何更改,则返回 nil。
Syntax: str.delete_prefix
Parameters: Here, str is the given string.
Returns: A copy of the given string with leading prefix deleted or nil if no change was made.
示例 1:
# Ruby program to demonstrate
# the delete_prefix! method
# Taking a string and
# using the method
puts "Ruby".delete_prefix!("Ru")
puts "Class".delete_prefix!("Cl")
输出:
by
ass
示例 2:
# Ruby program to demonstrate
# the delete_prefix! method
# Taking a string and
# using the method
puts "Sample".delete_prefix!("am")
puts "Input".delete_prefix!("In")
输出:
put