Newbie: text replacement in my case

前端 未结 2 1816
慢半拍i
慢半拍i 2021-01-27 06:49

In my Ruby on Rails app, I have a method in my helper which opened a file by:

content = File.open(myfile.txt)

The cont

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-27 07:11

    line.gsub!(/my/, "her")
    

    Although you may want to get more specific with the regular expression, e.g.

    line.gsub!(/\bmy\./, "her")
    

提交回复
热议问题