RooSoft
RooSoft

Reputation: 1501

How to remove backslashes in ruby strings

In ruby, I am trying to convert

'\"\"' 

to

'""' 

In short, what's the cleanest way to remove the backslashes?

Upvotes: 0

Views: 1477

Answers (3)

Cary Swoveland
Cary Swoveland

Reputation: 110755

Yet another:

'\"\"'.delete("\\") # => "\"\""

Upvotes: 1

Donovan
Donovan

Reputation: 15927

You can use the gsub method on any string to remove unwanted characters.

some_string.gsub('\\"', '"')

Upvotes: 2

Arup Rakshit
Arup Rakshit

Reputation: 118299

Use String#tr

s = '\"\"'
s.tr('\\', '') # => "\"\""

Upvotes: 0

Related Questions