红宝石 |字符串删除!方法
删除!是 Ruby 中的 String 类方法,用于执行删除操作,返回给定的字符串,如果给定的字符串没有被修改,则返回 nil。
Syntax: str.delete!(parameter_list)
Parameters: Here, str is the given string and parameter_list are the specified characters.
Returns: nil if the string not modified.
示例 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