From: Adam Prescott Date: 2010-10-04T21:05:26+09:00 Subject: Re: save only first line from string? >>> "a string\nwith multiple\nlines".split(/\n|\r\n/)[0] > => "a string" "a string\nwith multiple\nlines".split(/\r?\n/).first I was somewhat amazed to find not the split solution, but the rather wild (g)sub solutions as the first responses! On Mon, Oct 4, 2010 at 8:25 AM, Steel Steel wrote: > Terry Michaels wrote: >> Hi. What's the most simple and elegant way to remove all the contents of >> a String except for the first line? (Assume string consist of one line, >> multiple lines, or no lines, and assume that we don't know which OS we >> are on.) > > >>> "a string\nwith multiple\nlines".split(/\n|\r\n/)[0] > => "a string" > -- > Posted via http://www.ruby-forum.com/. > >