Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从字符串中删除 '\' 在 ruby on rails 中出现的任何位置。是否可以使用 gsub 或类似的东西?
例如考虑一个字符串,string = "hey boss\ how are you"。我需要让它打印为“嘿老板你好吗”。
'hey boss\ how are you'.tr('\\','')
'hey boss\ how are you'.delete!('\\') => "hey boss how are you"
如何使用:
'hey boss\ how are you'.gsub('\\',' ') => "hey boss how are you"