简体   繁体   中英

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?

您可以在任何字符串上使用gsub方法来删除不需要的字符。

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

完后还有:

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

Use String#tr

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM