Ruby 字符串 delete()方法
delete 是Ruby中的一个字符串类方法,用于返回一个给定字符串的副本,并删除其参数交集中的所有字符。
语法: str.delete(parameter_list)
参数: 这里,str是给定的字符串,参数_list是指定的字符。
返回: 一个新的字符串副本,删除其参数交集中的所有字符。
例子 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