On 4 October 2010 04:19, Terry Michaels <spare / frigidcode.com> 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.)
> --

Probably the most elegant, with Ruby 1.9:

str = str.lines.first

add ".chomp" if you want to remove the trailing EOL.