From: "Ian M. Asaff" Date: 2011-10-15T04:02:32+09:00 Subject: Re: Ruby functions to split numbers --00504502cd851f2fbf04af46e6db Content-Type: text/plain; charset=ISO-8859-1 ruby-1.9.2-p290 :010 > a = "01234567" => "01234567" ruby-1.9.2-p290 :011 > var1,var2 = [a[0,3],a[3,5]] => ["012", "34567"] ruby-1.9.2-p290 :012 > var1 => "012" ruby-1.9.2-p290 :013 > var2 => "34567" keep in mind that a number with a leading zero makes ruby think the base is octal: ruby-1.9.2-p290 :019 > 012 => 10 hope that helps. ian On Fri, Oct 14, 2011 at 2:52 PM, ideal one wrote: > HI All, > I have couple of requirements to be handled in ruby, it will be > great if anyone can shed some light on this. > > 1) i have a 8 digit number, to be used in my code as 2 parts(split), > like shown below. > > Number = "34502305" # I put them in double quotes, so that leading > zeros are preserved. > Var1 = 345 # split firs 3 digits always > Var2 = 02305 # split remaining digits with preserving leading Zero if > it exists > > i tried doing something like this, not sure if its correct > > sprintf("%2d", number) > > I am not able to preserve leading zero or i get fixnum to string error > > Cheers > > -- > Posted via http://www.ruby-forum.com/. > > --00504502cd851f2fbf04af46e6db--