Mithun Sasidharan Mithun Sasidharan - 1 year ago 77
Ruby Question

Replace words in string - ruby

I have a string in ruby

sentence = "My name is Robert"

How can i replace any one word in this sentence easily without using complex code or loop??

Answer Source

You can try using this way :

sentence ["Robert"] = "Roger"

Then the sentence will become :

sentence = "My name is Roger" # Robert is replaced with Roger
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download