From: Harry Kakueki Date: 2007-05-04T11:08:32+09:00 Subject: Re: Is there a better way to do this? On 5/4/07, Harry Kakueki wrote: > > > > > I am trying to come up with a "generic" formatting routine so that I > > could feed it something like sform("123456789", "000-00-0000") or > > sform("1234567890", "(000) 000-0000") or sform("123456", "00/00/00") and > > it would work. I could easily do something like you suggest, and for > > some cases it might be better, but I want something I can for any number > > of formats. Thanks for the input. > > > > > Well, that's different :) > So, you want to grab the first 10 digits and ignore beyond that? > Look into regular expressions. > Harry > > -- > http://www.kakueki.com/ruby/list.html > A Look into Japanese Ruby List in English > > This will grab digits and then you can do what you want with them. arr = ["1234567890", "(123) 867-5309","12/34/56/78/90444"] arr.each do |x| num = x.scan(/\d/).join p num puts end Harry -- http://www.kakueki.com/ruby/list.html A Look into Japanese Ruby List in English