From: Analogy Analogy Date: 2007-09-19T05:14:05+09:00 Subject: Re: converting text Sebastian Hungerecker wrote: > Analogy Analogy wrote: > >> I tried cutting and pasting this in SciTE to see if it works...it >> didn't, but thanks for directing me in the right direction. > > How does it not work? Both versions work just fine in irb: >>> ["1.80%", "14.50%", "ruby", "3.10%"].map do |string| >>> string.gsub(/\d+(\.\d+)?/) {|match| "%.1f" % match} >>> end > => ["1.8%", "14.5%", "ruby", "3.1%"] > >>> ["1.80%", "14.50%", "ruby", "3.10%"].map do |string| >>> string.gsub(/\d+(\.\d+)?/) {|match| match.to_f.to_s} >>> end > => ["1.8%", "14.5%", "ruby", "3.1%"] My fault, I stand corrected. Thank you sir! -- Posted via http://www.ruby-forum.com/.