From: Brian Candler Date: 2010-03-23T05:50:39+09:00 Subject: Re: splitting text string Joel VanderWerf wrote: > Jonathan Nielsen wrote: >>> order (first three) => 123 >>> stephen >> irb(main):004:0> status = barcode[8..8] >> => "9" >> >> -Jonathan Nielsen >> > > Another idea: > > $ irb -r scanf > >> "123456789".scanf("%3d%5d%1d") > => [123, 45678, 9] > > (note that the strings are converted to integers for you) Another: raise "Bad barcode" unless "123456789" =~ /\A(\d{3})(\d{5})(\d)\z/ order, product, status = $1, $2, $3 -- Posted via http://www.ruby-forum.com/.