红宝石 |字符串 delete() 方法
delete是 Ruby 中的 String 类方法,用于返回给定字符串的副本,其中删除了其参数交集中的所有字符。
Syntax: str.delete(parameter_list)
Parameters: Here, str is the given string and parameter_list are the specified characters.
Returns: A new copy of the string with all characters in the intersection of its arguments deleted.
示例 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