简体   繁体   English

从字符串中删除“ \\”

[英]Removing ' \ ' from a string

I need to remove '\\' from a string wherever it appears on it in ruby on rails. 我需要从字符串中出现在红宝石上的字符串中删除“ \\”。 Is it possible using gsub or anything similar to it ? 是否可以使用gsub或类似的东西?

For example consider a string, string = "hey boss\\ how are you". 例如,考虑一个字符串,字符串=“嘿老板\\您好吗”。 I need to make it to print as "hey boss how are you". 我需要将其打印为“嘿老板,你好吗”。

How about using: 如何使用:

'hey boss\ how are you'.gsub('\\',' ')     

=> "hey boss how are you" 
'hey boss\ how are you'.tr('\\','')
'hey boss\ how are you'.delete!('\\')
   => "hey boss how are you"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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