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

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

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

删除!是 Ruby 中的 String 类方法,用于执行删除操作,返回给定的字符串,如果给定的字符串没有被修改,则返回 nil。

示例 1:

# Ruby program to demonstrate 
# the delete! method 
       
# Taking a string and 
# using the method
str = "String Counting"
puts str.delete! "ing"

输出:

Str Cout

示例 2:

# Ruby program to demonstrate 
# the delete! method 
       
# Taking a string and 
# using the method
str = "String Counting"
puts str.delete! "ing", "^n"
  
str2 = "Ruby Method"
  
puts str2.delete! "ZXC"

输出:

Strn Countn