From: Eero Saynatkari Date: 2006-09-13T09:35:41+09:00 Subject: Re: word substitution in file Xan Xann wrote: > Eero Saynatkari wrote: >> # Untested too >> require 'fileutils' >> >> def FileUtils.s(source, dest, subs = {}) >> data = File.read source >> search = /#{subs.keys.map {|k| Regexp.escape k}.join '|'}/ >> result = data.gsub(search) {|found| subs[found]} >> File.open(dest, 'w') {|f| f.write result} if $& # Regex matched >> end >> >> FileUtils.s 'src.txt', 'dest.txt', 'foo' => 'bar' > > > This WORKS!!!! finally > > > Thank you very much > It seems it supports regexp expressions. Is it true? It just substitutes strings with their counterparts given as the Hash. Regular expression support would be a bit more involved. -- Posted via http://www.ruby-forum.com/.