Ruby 字符串 delete_prefix方法
delete_prefix 是Ruby中的一个字符串类方法,用于返回一个删除了前缀的给定字符串的副本。
语法: str.delete_prefix
参数: 这里,str是给定的字符串。
返回: 给定字符串的副本,删除前缀。
例子 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