📜  红宝石 |字符串 delete() 方法

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

红宝石 |字符串 delete() 方法

delete是 Ruby 中的 String 类方法,用于返回给定字符串的副本,其中删除了其参数交集中的所有字符。

示例 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\\r\\n"
  
puts str2.delete "\\"

输出:

Strn Countn
Ruby Methodrn