From: Adam Prescott Date: 2010-10-05T01:01:50+09:00 Subject: Re: save only first line from string? > I, perhaps erroneously, thought that the OP wanted to modify the string. Oh, yes, I missed that; I should pay more attention. On Mon, Oct 4, 2010 at 3:18 PM, John Sikora wrote: > Adam Prescott wrote: >>>>> "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! > > I, perhaps erroneously, thought that the OP wanted to modify the string. > If so, the split method seems somewhat inelegant, perhaps: > > string = string.split(/\n|\r\n/)[0]. So I posted the sub! way instead. > > js > -- > Posted via http://www.ruby-forum.com/. > >