Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!talisker.lacave.net!lacave.net!not-for-mail From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: Need help bringing select array lines together Date: Thu, 26 May 2011 17:31:01 -0500 Organization: Service de news de lacave.net Lines: 33 Message-ID: <5a14aeeff415a03ff1fe30fbe31114ee@ruby-forum.com> References: <20110526184256.54f1bcf6@killersmurf.com> <325f5d61-b988-47e4-8765-6aefdeebe6c9@p23g2000vbl.googlegroups.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1306449194 36845 65.111.164.187 (26 May 2011 22:33:14 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Thu, 26 May 2011 22:33:14 +0000 (UTC) In-Reply-To: <325f5d61-b988-47e4-8765-6aefdeebe6c9@p23g2000vbl.googlegroups.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 383826 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <5a14aeeff415a03ff1fe30fbe31114ee@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:5110 Paul wrote in post #1001335: > 2) I'm thinking about getting rid of the initial array and reading > the data straight from the input files. Okay. How about: require 'stringio' str =<<'ENDOFSTRING' "Only one line." "line 1 line 2 line 3" ENDOFSTRING file = StringIO.new(str) $/ = %Q{"\n} #change input line separator file.each do |line| line.chomp!("\n") line.gsub!("\n", ' ') p line end --output:-- "\"Only one line.\"" "\"line 1 line 2 line 3\"" -- Posted via http://www.ruby-forum.com/.