How to delete specific characters from a string in Ruby?

Cristiano picture Cristiano · Oct 28, 2013 · Viewed 173.5k times · Source

I have several strings that look like this:

"((String1))"

They are all different lengths. How could I remove the parentheses from all these strings in a loop?

Answer

Arup Rakshit picture Arup Rakshit · Oct 28, 2013

Do as below using String#tr :

 "((String1))".tr('()', '')
 # => "String1"