What do you get when you do puts lines ? This will give you the key.
By default, File.open opens the file in text mode, so your \r\n characters will be automatically converted to \n . Perhaps the reason for lines always equal to lines2 . To prevent Ruby string parsing, use rb mode:
C: \> copy con lala.txt
a
file
with
many
lines
^ Z
C: \> irb
irb (main): 001: 0> text = File.open ('lala.txt'). read
=> "a \ nfile \ nwith \ nmany \ nlines \ n"
irb (main): 002: 0> bin = File.open ('lala.txt', 'rb'). read
=> "a \ r \ nfile \ r \ nwith \ r \ nmany \ r \ nlines \ r \ n"
irb (main): 003: 0>
But from your question and code, I see that you just need to open the file using the default modifier. You do not need any conversion and can use the shorter File.read .
RΓ΄mulo Ceccon Nov 13 '08 at 19:03 2008-11-13 19:03
source share