using gsub in ruby strings correctly -


i have expression:

channelname = rhash["channel"].gsub("'", " ") 

it works fine. however, can substitute 1 character it. want add few more characters substitue. tried following:

channelname = rhash["channel"].gsub(/[':;] /, " ") 

this did not work, there no substitution done on strings , no error message. tried this:

channelname = rhash["channel"].gsub!("'", " ") 

this lead string blank. absolutely not desired.

i have gsub method substitute following characters space in string:

 ' ; : 

my questions:

  1. how can structure gsub method instances of above characters replaced space?

  2. what happening gsub! above returning blank.

your second attempt close. problem left space after closing bracket, meaning looking 1 of symbols followed space.

try this:

channelname = rhash["channel"].gsub(/[':;]/, " ") 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -