From: Xan Xann Date: 2006-09-13T18:39:07+09:00 Subject: Re: word substitution in file Eero Saynatkari wrote: > 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. Well, thanks you very much for your help Xan. -- Posted via http://www.ruby-forum.com/.