From: 7stud -- Date: 2008-03-07T02:03:15+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' duplicate = 2 new_str = "" str.each_byte do |byte| duplicate.times do new_str << byte end end puts new_str -- Posted via http://www.ruby-forum.com/.