红宝石 |字符串 delete_prefix 方法
delete_prefix是 Ruby 中的 String 类方法,用于返回给定字符串的副本,其中前导前缀已删除。
Syntax: str.delete_prefix
Parameters: Here, str is the given string.
Returns: A copy of the given string with leading prefix deleted.
示例 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")
输出:
Sample
put