I know I can easily remove a substring from a string.
Now I need to remove every substring from a string, if the substring is in an array.
arr = ["1. foo", "2. bar"]
string = "Only delete the 1. foo and the 2. bar"
# some awesome function
string = string.replace_if_in?(arr, '')
# desired output => "Only delete the and the"
All of the functions to remove adjust a string, such as sub
, gsub
, tr
, ... only take one word as an argument, not an array. But my array has over 20 elements, so I need a better way than using sub
20 times.
Sadly it's not only about removing words, rather about removing the whole substring as 1. foo
How would I attempt this?