From: Muralidharan Regupathy Date: 2009-04-04T04:06:04+09:00 Subject: Re: how to substitute group of words in a line with another text Robert Klemme wrote: > On 03.04.2009 20:10, Muralidharan Regupathy wrote: >> |key, value| >> tmpvalue = value.chomp.downcase >> msg=message.chomp.downcase >> puts "looking for <#{tmpvalue}> in <#{msg}>" >> newmsg=msg.gsub(tmpvalue,key) >> puts newmsg >> end >> >> the above mentioned code is not working, any help is appreciated > > If there are not many phrases you can use Regexp.union: > > msg.gsub Regexp.union(@smsdictionary.keys) do |match| > @smsdictionary[match] > end > > Kind regards > > robert Thanks Robert However i tried otherway and it seems to work fine. I know my solution is not a clean one but it works for my learning. def SMSdeflater(message) msg=message.chomp.downcase @smsdictionary.each_pair do |key, value| tmpvalue = value.chomp.downcase msg=msg.sub(tmpvalue,key) puts msg end end -- Posted via http://www.ruby-forum.com/.