简体   繁体   中英

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 ?

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"

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