From: 7stud -- Date: 2008-03-07T01:57:40+09:00 Subject: Re: duplicating characters in a string Adam Akhtar wrote: > >> Ask 10 Ruby programmers this question and I'm sure you'll get 11 >> different answers. If your definition of 'best' is 'fastest' you'll >> simply have to code and benchmark a couple of solutions. > > Well actually im new to ruby so although fastest/best solutions would be > appreciated I'd actually prefer ones that were not to advanced or > cryptic to read but at the same time not to innefficent. > > Thanks so far for your suggestions!! str = 'abc' repeat = 2 new_str = "" 0.upto(str.length) do |i| new_str << str[i, 1] * repeat end puts new_str -- Posted via http://www.ruby-forum.com/.