[Michael Hayes]:
>> Provided you're iterating over each line you could use:
>> "newlines \r\n".gsub /(\r|\n)/, ''
> 
> Close, but if the line contains an embedded \r
> it will get deleted.  (I didn't mention that
> requirement in my post, so you are forgiven :-)
> 
> The semantics I want are:
> 
>     - If the string does not end with \n then
>       leave it alone.
> 
>     - If the string ends with \n then remove it.
> 
>     - if the character preceding the \n is \r
>       then remove that too.
> 
> I'm sure it's possible to do it with sub or gsub,

Try

    s.sub /\r?\n\z/, ''

// Niklas