From: ronald braswell Date: 2007-08-08T02:12:42+09:00 Subject: Re: array.each puzzle from new ruby-er ------=_Part_48214_33507980.1186506766892 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/7/07, ronald braswell wrote: > > > > On 8/7/07, Gani Ruthellen wrote: > > > > Given: > > lines = file.readlines("\x15") # don't ask :) > > lines.each do |y| > > y.chomp!("\x15") > > y.sub!(/^\n/,"") #kill off the extra line feeds > > if y =~ /^\*\*\*/ then > > y = "" + y + "" > > ... > > [ assume ends] > > puts lines > > > > my output for the affected elements is: > > > > value of y > > > > How can I get the results to be > > value of y > > > > I've tried changing y to y.to_s; I still get the new line. > > > > I'm sure this is obvious if you know what you're doing, but I'm stumped. > > > > Can somebody give me a clue? > > > > TIA if you take a moment to point me in the right direction. > > Gani > > -- > > Posted via http://www.ruby-forum.com/. > > > Hi Gani, > > try > y.gsub!(/^\n/,"") #kill off the extra line feeds > instead of > y.sub!(/^\n/,"") #kill off the extra line feeds > > Ron > > Oops. That would not be any different because of the ^anchor. y.sub!(/^\n+/,"") might do the trick. Ron ------=_Part_48214_33507980.1186506766892--